So I've been trying to figure out a way to call AHK code when a user clicks a button or link in an IE window, *without* using an embedded AHK GUI. The reason I'm trying to avoid embedding IE in a GUI is it seems to break keyboard navigation (and accessibility is an important part of this project - and every project IMO but especially here). Pressing Tab seems to move the focus outside the embedded browser and into... something else. So that's not going to work here. So here's what I've got so far...
; test.ahk - slightly modified from the AHK docs on ComObjConnect
ie := ComObjCreate("InternetExplorer.Application")
; Connects events to corresponding script functions with the prefix "IE_".
ie.Visible := true ; This is known to work incorrectly on IE7.
ie.Navigate(A_ScriptDir . "\test.html")
; Does nothing / event not fired / ???
; No message box, no errors, nuttin (again with the ??? lol)
window := document.parentWindow
MsgBox % element.id
; test.html - worked with an embedded GUI (another copy/paste off some forum post, but nothing too fancy here)
; EDIT: Note the "tabindex='0'" in the link - this was an attempt to fix the focus issue mentioned above when using an embedded GUI - didn't work)
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<input type='text' id='Edit'/><br />
<a href='#' id='Box' tabindex='0'>Show AHK message box</a>
Then when I restart or exit the script, I get any number of cryptic errors (ranging from "the interface is unknown" to "object invoked disconnected from blah blah deeblahdee blah" - lol). So I'm obviously missing something, gotta be something slight'n'stupid (as most bugs are) but so far it's code 1 me 0. lol idk - any clues would be greatly appreciated.