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...
Code: Select all
; test.ahk - slightly modified from the AHK docs on ComObjConnect
ie := ComObjCreate("InternetExplorer.Application")
; Connects events to corresponding script functions with the prefix "IE_".
ComObjConnect(ie, "IE_")
ie.Visible := true ; This is known to work incorrectly on IE7.
ie.Navigate(A_ScriptDir . "\test.html")
#Persistent
; Does nothing / event not fired / ???
; No message box, no errors, nuttin (again with the ??? lol)
IE_OnClick(document)
{
window := document.parentWindow
element:= window.event.srcElement
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)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<body>
<input type='text' id='Edit'/><br />
<a href='#' id='Box' tabindex='0'>Show AHK message box</a>
</body>
</html>