tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Tue Jul 17, 2007 8:29 am Post subject: Timer weirdness with JavaScript in an embedded IE control |
|
|
JavaScript timers (Windows timers) do not work in HTML pages displayed using an embedded IE control. Interestingly, if a MsgBox is opened the timers will start to work. When the MsgBox is closed the timers stop working.
Similar symptoms without JavaScript were reported in this thread: BalloonTip.
This example demonstrates the problem. Copy both files to the same directory. Requires CoHelper.ahk and IEControl.ahk. Tested with AHK version 1.0.47.01.
Test.ahk | Code: | #Include CoHelper.ahk
#Include IEControl.ahk
CoInitialize()
AtlAxWinInit()
Gui, +LastFound
Gui, Show, w200 h50 x50 y50, Timer Weirdness
hWnd := WinExist()
pwb := ActiveXObject("Shell.Explorer")
AtlAxAttachControl(pwb, hWnd)
IE_LoadURL(pwb, A_ScriptDir . "\Test.html")
Hotkey, IfWinActive, ahk_id %hWnd%
Hotkey, ^m, NewMsgBox
; While a msgbox exists the JavaScript timer works.
; The msgbox does not need to be active or visible.
; Close the msgbox and the JavaScript timer stops working
GoSub NewMsgBox
Return
NewMsgBox:
MsgBox,, AHK MsgBox,
(LTrim
Close this AHK MsgBox and the timer used by JavaScript stops working.
Open a new MsgBox with the hotkey ^m and the timers will start working again.
)
Return
GuiClose:
Gui, Destroy
Release(pwb)
AtlAxWinTerm()
CoUninitialize()
ExitApp
Return
|
Test.html (works properly when opened in Internet Explorer) | Code: | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
setTimeout("showmsg()",500); //First time only, the timer fires after 0.5 sec
function showmsg(){
var msg = 'This JavaScript message appears whenever the timer fires. ' +
'As long as the AHK MsgBox exists the timer works. ' +
'As soon as the AHK MsgBox is closed the timer stops working. ' +
'Click OK to close this dialog and reset the timer.' ;
alert(msg)
setTimeout("showmsg()",2000); //Timer fires after 2 sec
}
</script>
</head>
<body></body>
</html>
|
This is a much simpler example than the one discussed in this thread JavaScript Tooltip in an embedded IE Control. |
|