我正在尝试使用IE ActiveX控件动态更新Autohotkey GUI,但遇到了奇怪的行为。请帮忙。
; ie-refresh.ahk on Autohotkey 1.1.24
global WB
Gui, Font, s9 cBlack, Tahoma
Gui, Add, Text, , % "Click button to see html content."
Gui, Add, ActiveX, xm w120 h30 vWB, Shell.Explorer
Gui, Add, Button, xm gBtnClicked, % "Update html text"
Gui Show
return
BtnClicked()
{
html_tmpl =
( Ltrim Join
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0px;
color: red;
}
</style>
</head>
<body>
Count: {}
</body>
</html>
)
static snum := 0
snum++
html_code := Format(html_tmpl, snum)
WB.Navigate("about:blank")
WB.document.write(html_code)
}
GuiEscape:
GuiClose:
ExitApp
当我单击按钮时,IE内容会更新,但它只会更新两次。
在第三个按钮单击,IE内容区域几乎肯定显示为空白。
继续单击按钮,红色文本会间歇性地随机出现,十分之一点击一下。
那我的代码出了什么问题?
问题似乎是第二次调用导航。
我认为WB.Stop()会解决问题,但之后你会发现WB.Navigate还不足以清理屏幕所以......
最明智的选择看起来像是在gui-add(或之后的某个地方)之后放置WB.Navigate,然后使用WB.Refresh()。
仅供参考,一些WebBrowser Control文档qazxsw poi。
虽然我无法解释我的问题中的奇怪行为,但我已设法找到解决方案来满足我的要求。
使用以下代码:
here
首先,只打电话给; ie-refresh.ahk on Autohotkey 1.1.24
global WB
Gui, Font, s9 cBlack, Tahoma
Gui, Add, Text, , % "Click button to see html content."
Gui, Add, ActiveX, xm w120 h30 vWB, Shell.Explorer
Gui, Add, Button, xm gBtnClicked, % "Update html text"
WB.Navigate("about:blank")
Gui Show
return
BtnClicked()
{
html_tmpl =
( Ltrim Join
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0px;
color: red;
}
</style>
</head>
<body>
Count: {}
</body>
</html>
)
static snum := 0
snum++
html_code := Format(html_tmpl, snum)
WB.document.open()
WB.document.write(html_code)
WB.document.close()
}
GuiEscape:
GuiClose:
ExitApp
一次。
其次,当我需要更新整个html文档时,我需要打开+ write + close。
现在它可靠地工作。