I was trying to interact with a webpage with autoit and the stupid javascript alerts kept breaking everything and I finally figured out how to disable them so I thought I would post it here:
#include <ie.au3>
$oIE = _IEAttach( https://www.site.com , URL )
$EventObject=ObjEvent($oIE.document,"IEEvent_")
Func IEEvent_onreadystatechange()
$readystate=$oIE.document.readystate
ConsoleWrite ($readystate & @CRLF )
if $readystate= interactive then killalert()
EndFunc
while 1
sleep(100)
WEnd
func killalert()
Local $o_head = $oIE.document.all.tags("HEAD").Item(0)
Local $o_script = $oIE.document.createElement("script")
With $o_script
.language = "jscript"
.type = "text/javascript"
.text = function alert(message) {};
EndWith
$o_head.appendChild($o_script)
EndFunc
Basically what this does is have a function get called in autoit when the page ready status= interactive (apparently this is after most of the page has loaded but before it "runs" anything i think) that inserts some javascript into the page to redefine the alert() function so that it does nothing (no alert dialog to worry about having to click ok on). I have tested this and it works.
If you have the alert() function being called from a frame inside the page then you will have to use the onreadystatechange event and the readystate property of the frame instead of the main document.