【问题标题】:How to display html content in a div and add a content the html file in HTA如何在 div 中显示 html 内容并在 HTA 中添加 html 文件的内容
【发布时间】:2021-12-08 23:46:23
【问题描述】:

我只需关注tutorial就成功创建了一个简单的基于网络的聊天应用程序

唯一的区别是我没有包括登录的东西。它只会在 log.html 中不断发布消息。

现在我正在尝试在 HTA 中执行此操作。这是我第一次使用它。我还在学习,目前正在学习:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <meta charset="utf-8" />
        <title>Chat-App</title>
        <meta name="description" content="Chat-App" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <link rel="stylesheet" type="text/css" href="font-awesome-animation.min.css"/>
        <link rel="stylesheet" href="styles.css" />
        
    <HTA:APPLICATION 
         SCROLL="auto"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"/>
     <script language="VBScript">
            Sub window_OnLoad
             Window.ResizeTo 680,723
              iTimerID = window.setInterval("Display", 1000)
            End Sub
            
                strPath = "C:\Users\username\Desktop\Chat App\"
                Set wshShell = CreateObject( "WScript.Shell" )
                'strSender = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
            
            Sub Display
                Set objFSO = CreateObject("Scripting.FileSystemObject")
            
            Set objFile = objFSO.OpenTextFile(StrPath & "log.html", 1)
             strCharacters = objFile.ReadAll
            
            
             objFile.Close
             chatbox.innerHTML = strCharacters
             chatbox.ScrollTop = chatbox.ScrollHeight
            
            End Sub
        </script>
    </head>
    
    <body style="background-color:grey;">
        <div id="wrapper">
            <h1 style="margin-top: 5px;margin-left:20px;color:orange;">Chat-App</h1>

            <div id="chatbox" name="chatbox" class="textbox">
            </div>
 
            <form name="message" action="">
                <textarea rows="10" cols="30" name="usermsg" type="text" id="usermsg" style="height:200px;" placeholder="Type your message here..."></textarea>
                <input name="submitmsg" type="submit" id="submitmsg" value="Send" />
            </form>
        </div>
  </body>
</html>

这是输出 ..ChatApp

这只会获取 log.html 的内容,然后显示在聊天框 div 中。但它有一个错误,说“显示”未定义。而且 textarea 看起来甚至不像 textarea。

除此之外,我不知道如何在 log.html 中实现发布消息并像教程中那样每隔几秒刷新一次。我尝试粘贴基于 Web 的 javascript,但是当我将其转换为 hta 时它不起作用。有人可以帮我在 HTA 中做吗?

【问题讨论】:

    标签: html vbscript jscript hta


    【解决方案1】:

    Official Documentation has the answer

    语法

    retVal = object.setInterval(expression, msec, language);
    

    参数

    • 表达式 [in] 类型:VARIANT

      指向指定函数指针或字符串的 VARIANT 的指针 表示当指定的时间间隔有时要执行的代码 已过。

    • msec [in] 类型:long

      long 指定毫秒数。

    • 语言 [in,可选] 类型:VARIANT

      指向 BSTR 的指针,它指定了 IHTMLElement::language 属性。

    这里的重要参数是language,因为它告诉setInterval() expression 是用特定语言(JScript、VBScript 等)编写的。

    换行:

    iTimerID = window.setInterval("Display", 1000)
    

    到:

    iTimerID = window.setInterval("Display", 1000, "VBScript")
    

    【讨论】:

    • 哦...是的,它非常有效!现在如何在 textarea 中输入消息并将其发布到 log.html 然后将显示在聊天框 div 中?就像在教程中一样..
    • @NewbieKid 这不是我们能够在这里回答的问题。但是,我建议回到教程并查看“第 4 步:处理用户输入”,您可能还需要一些服务器端 PHP、Classic ASP 或 ASP.Net 等来将消息发布到。
    • @NewbieKid 如果最初的问题已经得到解答并且您已经能够取得进展,请考虑up-voting and accepting this answer
    • 我已经尝试过将 jquery 与 post.php 一起使用,就像在教程中一样,它在 HTA 中不起作用。也许如果有人可以使该 jquery 函数的 hta 语法相等,那对我来说将是一个很大的帮助..
    • 当我尝试添加一个javascript代码时,它说“$”是未定义的。
    【解决方案2】:

    这是一个简单的 HTA 聊天框应用程序,您可以使用它来制作自己的版本。您可以在同一台计算机上运行多个副本,或者将聊天日志文件设置为共享驱动器上的路径并在多台计算机上运行。

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=9">
    <hta:application
      id=oHTA
      icon=notepad.exe
      applicationname=ChatBox
      selection=yes
      singleinstance=no
    >
    <script>    
    function Refresh() {
      Iframe = document.getElementById("chatbox").contentWindow;
      window.setInterval(function() {
        fso = new ActiveXObject("Scripting.FileSystemObject");
        fh = fso.OpenTextFile(ChatLog,1,1);
        FileContents = fh.AtEndOfStream ? "" : fh.ReadAll();
        fh.Close();
        Iframe.document.body.innerHTML = FileContents
        if (autoscroll.checked) {Iframe.scrollTo( 0,999999)};
      }, 500);
    }
    function replaceAll(str, match, replacement){
       return str.split(match).join(replacement);
    }
    function PostMsg() {
      TrimMsg = replaceAll(msg.value.trim(),'\n','<br>');
      if (TrimMsg.length > 0) {
        fh = fso.OpenTextFile(ChatLog,8);
        UserName = user.value.trim();
        if (UserName=='') {UserName = 'Anonymous'};
        fh.write('<button>' + UserName + '</button><br><div>' + TrimMsg + '</div><br>');
        fh.Close();
      }
    }
    </script>
    <style>
    body {background-color:grey}
    #chatbox {background-color:white; height:30em; width:30em}
    #sb {float:right}
    </style>
    </head>
    <body onload=Refresh()>
      <script>
        document.title = "Chat Box"
        ChatLog = ".\\Chat.txt";
        x = 520;
        y = 680;
        window.resizeTo(x, y);
        window.moveTo((screen.availWidth - x)/2, (screen.availHeight - y)/2);
        </script>
      <iframe id=chatbox title="Chat Box"></iframe><br><br>
      <textarea id=msg rows=4 cols=58></textarea><br><br>
      Screen name:<input type=text id=user>
      Autoscroll:<input type=checkbox checked id=autoscroll>
      <input type=button id=sb value=Send OnClick=PostMsg()>
    </body>
    </html>
    

    【讨论】:

      猜你喜欢
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-13
      • 2012-05-28
      • 2014-03-22
      • 2017-10-06
      • 1970-01-01
      相关资源
      最近更新 更多