我通过简单地遵循此 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的内容然后显示在chatbox div中。但它有一个错误,说“显示”未定义。而且 textarea 看起来根本不像 textarea。
除此之外,我不知道如何在 log.html 中实现发布消息并像教程中那样每隔设定的秒刷新一次。我尝试粘贴在基于 Web 中工作的 javascript,但当我将其转换为 hta 时它不起作用。有人可以帮我在 HTA 中做到这一点吗?
最佳答案
Official Documentation has the answer
Syntax
retVal = object.setInterval(expression, msec, language);
Parameters
expression [in] Type: VARIANT
Pointer to a VARIANT that specifies a function pointer or string that indicates the code to be executed when the specified interval has elapsed.
msec [in] Type: long
long that specifies the number of milliseconds.
language [in, optional] Type: VARIANT
Pointer to a BSTR that specifies any one of the possible values for the IHTMLElement::language attribute.
这里的重要参数是语言
,因为它告诉setInterval()
表达式
是用特定语言(JScript、VBScript)编写的等)。
更改行:
iTimerID = window.setInterval("Display", 1000)
至:
iTimerID = window.setInterval("Display", 1000, "VBScript")
关于html - 如何在div中显示html内容并在HTA中的html文件中添加内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69675054/