Jump to content

IE Embedded - capturing events


Recommended Posts

Perhaps using the document title to exchange a text reference of the input changed

This is a try not fully working:

;From: Gianni, Oct 10 2022
;https://www.autoitscript.com/forum/topic/197979-ie-embedded-capturing-events/?do=findComment&comment=1508094
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $g_idGUIEdit

Example()
Exit ; End of our Demo.

Func Example()
    Local $hGUIMain = GUICreate("Event Test", 1000, 600)
    $g_idGUIEdit = GUICtrlCreateEdit("", 5, 405, 990, 175)
    ; GUICtrlSetBkColor(-1, 0x000000)
    ; GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetFont(-1, 9, 400, -1, 'Courier New')
    GUICtrlCreateLabel("Below are some Browser events 'captured' from the above web page by AutoIt", 5, 385, 990, 20)
    Local $idGUIExit = GUICtrlCreateButton(" Close and exit", 5, 580, 990, 15)
    GUISetState() ;Show GUI

    ; We prepare the Internet Explorer as our test subject
    Global $oIE = ObjCreate("Shell.Explorer.2")
    $hIE = GUICtrlCreateObj($oIE, 5, 5, 990, 380) ; <- insert $oIE in the AutoIt GUI

    ; Here we load an example Web page just to have something viewed in the browser
    ;$oIE.navigate('http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onmousemoveEX.htm')

    ;>>>>
    ;These lines from: Chimp, Jan 2017 (edited)
    ;Who is Who ? (a little drag&drop game)
    ;https://www.autoitscript.com/forum/topic/186422-who-is-who-a-little-dragdrop-game/
    ;Global $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl
    ;Local $hGUI = GUICreate("", 660, 600, 30, 30)
    ;GUICtrlCreateObj($oIE, 0, 0, 660, 600) ; Place BrowserControl on the GUI
    ;GUISetState() ;Show GUI
    $oIE.navigate('about:blank') ; file:///' & @ScriptDir & '\WhoIsWho.html')
    While Not String($oIE.readyState) = 'complete' ; wait for about:blank
        Sleep(100)
    WEnd

    ; this waits till the document is ready to be used (portion of code from IE.au3)
    While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4)
        Sleep(100)
    WEnd
    While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4)
        Sleep(100)
    WEnd

    $oIE.document.Write(_GetHTML()) ; inject lising directly to the HTML document:
    $oIE.document.close() ; close the write stream
    $oIE.document.execCommand("Refresh")
    While Not String($oIE.readyState) = 'complete' ; wait for readyState after a refresh
        Sleep(100)
    WEnd

    $oDocument = $oIE.document
    ;>>>>

;~     Sleep(1000) ; Give it some time to load the web page
;~     Do ; wait for document
;~         Sleep(250)
;~         $oDocument = $oIE.document
;~     Until IsObj($oDocument)

    ;   +  Scripting Object Interfaces
    ;   |  ---------------------------
    ;   |  https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx
    ;   |
    ;   +-->   HTMLDocumentEvents2 interface (catch OnClick, OnMouseOver, .... etc
    ;          -----------------------------
    ;          https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx
    ;
    Global $oEventObject = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents2")

    If @error Then
        MsgBox($MB_OK, "AutoIt COM Test", _
                "ObjEvent: Can't use event interface 'HTMLDocumentEvents2'. Error code: " & Hex(@error, 8))
        Exit
    EndIf

    Global $oEventObjectIE = ObjEvent($oIE, "IEEventIE_", "TitleChange")
    If @error Then
        MsgBox($MB_OK, "AutoIt COM Test", _
                "ObjEvent: Can't use event interface 'TitleChange'. Error code: " & Hex(@error, 8))
        Exit
    EndIf

    ; Waiting for user to close the GUI.
    Local $iMsg
    While 1
        $iMsg = GUIGetMsg()
        If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $idGUIExit Then ExitLoop
    WEnd

    $oEventObject.Stop ; Tell IE we don't want to receive events.
    $oEventObject = 0 ; Kill the Event Object
    $oIE = 0 ; Remove IE from memory (not really necessary).

    GUIDelete() ; Remove GUI
EndFunc   ;==>Example

; A few Internet Explorer Event Functions
; ( reference to the Event Obj interface: )
; ( https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx )
;

Volatile Func IEEventIE_TitleChange($oEvent)
    ConsolePrint("TitleChange: " & $oIE.Document.Title)
    ConsolePrint("TitleChange: " & $oIE.document.GetElementById($oIE.Document.Title))
EndFunc   ;==>IEEvent2_TitleChange

Volatile Func IEEvent2_onClick($oEvent)
    ConsolePrint("mouse click: " & $oEvent.clientX & ',' & $oEvent.clientY & '  on ' & $oEvent.srcElement.NodeName & '  id: ' & $oEvent.srcElement.id)
    If $oEvent.srcElement.NodeName = "INPUT" Then
        If $oEvent.srcElement.type = "radio" Or $oEvent.srcElement.type = "checkbox" Then
            If $oEvent.srcElement.checked = True Then
                ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " True")
            Else
                ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " False")
            EndIf
        EndIf
    EndIf
EndFunc   ;==>IEEvent2_onClick

Volatile Func IEEvent2_onDblClick($oEvent)
    ConsolePrint("mouse DoubleClick: @" & $oEvent.clientX & ',' & $oEvent.clientY)
EndFunc   ;==>IEEvent2_onDblClick

;~ Volatile Func IEEvent2_onMouseMove($oEvent)
;~     ConsolePrint("mouse moved to:" & @TAB & "Xpos = " & $oEvent.clientX & @TAB & "Ypos = " & $oEvent.clientY)
;~ EndFunc   ;==>IEEvent2_onMouseMove

; ===================================
Volatile Func IEEvent_Input_onkeydown($oEvent) ; onChange($oEvent)
    ConsolePrint("KeyCode: " & $oEvent.keyCode)
EndFunc   ;==>IEEvent_Input_onkeydown

Volatile Func IEEvent_Input_onkeypress($oEvent)
    ; Fires when you exit from the input and ONLY IF YOU HAVE CHANGED IT'S CONTENT
    ;                ----                    -------------------------------------
    ConsolePrint('Input content in "First name" field has changed')
EndFunc   ;==>IEEvent_Input_onkeypress
; ===================================

Func ConsolePrint($sMsg)
    Local Const $iMaxLines = 9 ; keep last 9 log lines only
    $sMsg = @HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $sMsg & @CRLF
    $sMsg = StringReplace(GUICtrlRead($g_idGUIEdit) & $sMsg, @CR, @CR)
    If @extended > $iMaxLines Then ; more than $iMaxLines
        $sMsg = StringMid($sMsg, StringInStr($sMsg, @CR, 0, -1 * $iMaxLines) + 2)
    EndIf
    GUICtrlSetData($g_idGUIEdit, $sMsg)
EndFunc   ;==>ConsolePrint

Func _GetHTML()
    ;form html code from: Marc Clifton, 16 Feb 2013, https://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values
    ;JavaScript from: Marijn Haverbeke (2011), Eloquent JavaScript: a modern introduction to programming. No Starch Press, Inc.
    Local $sHTML = _
            "<!DOCTYPE HTML>" & @CRLF & _
            "<html>" & @CRLF & _
            "<head>" & @CRLF & _
            "<meta http-equiv='X-UA-Compatible' content='IE=edge' />" & @CRLF & _
            "<title>Test</title>" & @CRLF & _
            "</head>" & @CRLF & _
            "<body>" & @CRLF & _
            "<form>First name: <input id='firstname' type='text' name='firstname'/>" & @CRLF & _
            "<br>" & @CRLF & _
            "Last name: <input id='lastname' type='text' name='lastname'/>" & @CRLF & _
            "<br>" & @CRLF & _
            "Password: <input id='password' type='password' name='pwd'/>" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='radio' id='male' name='sex' value='male'/>Male" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='radio' id='female' name='sex' value='female'/>Female" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='checkbox' id='bike' name='vehicle' value='Bike'/>I have a bike" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='checkbox' id='car' name='vehicle' value='Car'/>I have a car" & @CRLF & _
            "</form>" & @CRLF & _
            "" & @CRLF & _
            "<script type='text/javascript'>" & @CRLF & _
            "var firstname2 = document.getElementById('firstname');" & @CRLF & _ ; <- changed firstname to firstname2
            "var lastname = document.getElementById('lastname');" & @CRLF & _
            "var password = document.getElementById('password');" & @CRLF & _
            "var male = document.getElementById('male');" & @CRLF & _
            "var female = document.getElementById('female');" & @CRLF & _
            "var bike = document.getElementById('bike');" & @CRLF & _
            "var car = document.getElementById('car');" & @CRLF & _
            "" & @CRLF & _
            "//Marijn Haverbeke (2011), Eloquent JavaScript: a modern introduction to programming. No Starch Press, Inc." & @CRLF & _
            "var output = dom('DIV', {id: 'printOutput'}, dom('H3', null, 'Print output:'));" & @CRLF & _
            "window.onload = document.body.appendChild(output);" & @CRLF & _
            "// print('Hello');" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(firstname2, 'change', function(event) {" & @CRLF & _ ; <- changed firstname to firstname2
            "event = event || window.event;" & @CRLF & _
            "print(event.srcElement.value);" & @CRLF & _
            "document.title = 'event.srcElement.id';" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(lastname, 'change', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "print(event.srcElement.value);" & @CRLF & _
            "document.title = 'event.srcElement.id';" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(password, 'change', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "print(event.srcElement.value);" & @CRLF & _
            "document.title = 'event.srcElement.id';" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(male, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  //ok" & @CRLF & _
            "  print(event.srcElement.outerHTML +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  //Not working (tested with Internet Explorer 7)" & @CRLF & _
            "  //print(event.srcElement.GetAttribute('name'));" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(female, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  print(event.srcElement.outerHTML +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "//Returning always true ?" & @CRLF & _
            "registerEventHandler(bike, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  print(event.srcElement.value +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "//Returning always true ?" & @CRLF & _
            "registerEventHandler(car, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  print(event.srcElement.value +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  //Not working (tested with Internet Explorer 7)" & @CRLF & _
            "  //print(car.GetAttribute('checked'));" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "function registerEventHandler(node, event, handler) {" & @CRLF & _
            "if (typeof node.addEventListener == 'function')" & @CRLF & _
            "node.addEventListener(event, handler, false);" & @CRLF & _
            "else" & @CRLF & _
            "node.attachEvent('on' + event, handler);" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function print() {" & @CRLF & _
            "var result = [];" & @CRLF & _
            "forEach(arguments, function(arg){result.push(String(arg));});" & @CRLF & _
            "output.appendChild(dom('PRE', null, result.join('')));" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function dom(name, attributes, children) {" & @CRLF & _
            "var node = document.createElement(name);" & @CRLF & _
            "if (attributes) {" & @CRLF & _
            "forEachIn(attributes, function(name, value) {" & @CRLF & _
            "node.setAttribute(name, value);" & @CRLF & _
            "});" & @CRLF & _
            "}" & @CRLF & _
            "for (var i = 2; i < arguments.length; i++) {" & @CRLF & _
            "var child = arguments[i];" & @CRLF & _
            "if (typeof child == 'string')" & @CRLF & _
            "child = document.createTextNode(child);" & @CRLF & _
            "node.appendChild(child);" & @CRLF & _
            "}" & @CRLF & _
            "return node;" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function forEachIn(object, action) {" & @CRLF & _
            "for (var property in object) {" & @CRLF & _
            "if (object.hasOwnProperty(property))" & @CRLF & _
            "action(property, object[property]);" & @CRLF & _
            "}" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function forEach(array, action) {" & @CRLF & _
            "for (var i = 0; i < array.length; i++)" & @CRLF & _
            "action(array[i]);" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "</script>" & @CRLF & _
            "</body>" & @CRLF & _
            "</html>"
    Return $sHTML
EndFunc   ;==>_GetHTML

 

Link to comment
Share on other sites

This ok:

;Gianni, Oct 10 2022
;https://www.autoitscript.com/forum/topic/197979-ie-embedded-capturing-events/?do=findComment&comment=1508094
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $g_idGUIEdit

Example()
Exit ; End of our Demo.

Func Example()
    Local $hGUIMain = GUICreate("Event Test", 1000, 600)
    $g_idGUIEdit = GUICtrlCreateEdit("", 5, 405, 990, 175)
    ; GUICtrlSetBkColor(-1, 0x000000)
    ; GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetFont(-1, 9, 400, -1, 'Courier New')
    GUICtrlCreateLabel("Below are some Browser events 'captured' from the above web page by AutoIt", 5, 385, 990, 20)
    Local $idGUIExit = GUICtrlCreateButton(" Close and exit", 5, 580, 990, 15)
    GUISetState() ;Show GUI

    ; We prepare the Internet Explorer as our test subject
    Global $oIE = ObjCreate("Shell.Explorer.2")
    $hIE = GUICtrlCreateObj($oIE, 5, 5, 990, 380) ; <- insert $oIE in the AutoIt GUI

    ; Here we load an example Web page just to have something viewed in the browser
    ;$oIE.navigate('http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onmousemoveEX.htm')

    ;>>>>
    ;These lines from: Chimp, Jan 2017 (edited)
    ;Who is Who ? (a little drag&drop game)
    ;https://www.autoitscript.com/forum/topic/186422-who-is-who-a-little-dragdrop-game/
    ;Global $oIE = ObjCreate("Shell.Explorer.2") ; Create a BrowserControl
    ;Local $hGUI = GUICreate("", 660, 600, 30, 30)
    ;GUICtrlCreateObj($oIE, 0, 0, 660, 600) ; Place BrowserControl on the GUI
    ;GUISetState() ;Show GUI
    $oIE.navigate('about:blank') ; file:///' & @ScriptDir & '\WhoIsWho.html')
    While Not String($oIE.readyState) = 'complete' ; wait for about:blank
        Sleep(100)
    WEnd

    ; this waits till the document is ready to be used (portion of code from IE.au3)
    While Not (String($oIE.readyState) = "complete" Or $oIE.readyState = 4)
        Sleep(100)
    WEnd
    While Not (String($oIE.document.readyState) = "complete" Or $oIE.document.readyState = 4)
        Sleep(100)
    WEnd

    $oIE.document.Write(_GetHTML()) ; inject lising directly to the HTML document:
    $oIE.document.close() ; close the write stream
    $oIE.document.execCommand("Refresh")
    While Not String($oIE.readyState) = 'complete' ; wait for readyState after a refresh
        Sleep(100)
    WEnd

    $oDocument = $oIE.document
    ;>>>>

;~     Sleep(1000) ; Give it some time to load the web page
;~     Do ; wait for document
;~         Sleep(250)
;~         $oDocument = $oIE.document
;~     Until IsObj($oDocument)

    ;   +  Scripting Object Interfaces
    ;   |  ---------------------------
    ;   |  https://msdn.microsoft.com/en-us/library/hh801967(v=vs.85).aspx
    ;   |
    ;   +-->   HTMLDocumentEvents2 interface (catch OnClick, OnMouseOver, .... etc
    ;          -----------------------------
    ;          https://msdn.microsoft.com/en-us/library/aa769764(v=vs.85).aspx
    ;
    Global $oEventObject = ObjEvent($oDocument, "IEEvent2_", "HTMLDocumentEvents2")
    If @error Then
        MsgBox($MB_OK, "AutoIt COM Test", _
                "ObjEvent: Can't use event interface 'HTMLDocumentEvents2'. Error code: " & Hex(@error, 8))
        Exit
    EndIf

   ;From: Web Browsing Objects for VB Developers
   ;Objects
   ;...
   ;WebBrowser Object
   ;...
   ;TitleChange Event
   ;Occurs when the title of a document in the WebBrowser control becomes available or changes. For HTML, the title may change; while HTML is still downloading, the URL of the document is set as the title. After the real title (if there is one) is parsed from the HTML, the title is changed to reflect the actual title.
   ;Private Sub object_TitleChange(ByVal Text As String)
   ;object
   ;An object expression that evaluates to an object in the Applies To list.
   ;Text
   ;A string containing the new document title.
    Global $oEventObjectIE = ObjEvent($oIE, "IEEventIE_", "TitleChange")
    If @error Then
        MsgBox($MB_OK, "AutoIt COM Test", _
                "ObjEvent: Can't use event interface 'TitleChange'. Error code: " & Hex(@error, 8))
        Exit
    EndIf

    ; Waiting for user to close the GUI.
    Local $iMsg
    While 1
        $iMsg = GUIGetMsg()
        If $iMsg = $GUI_EVENT_CLOSE Or $iMsg = $idGUIExit Then ExitLoop
    WEnd

    $oEventObject.Stop ; Tell IE we don't want to receive events.
    $oEventObject = 0 ; Kill the Event Object
    $oIE = 0 ; Remove IE from memory (not really necessary).

    GUIDelete() ; Remove GUI
EndFunc   ;==>Example

; A few Internet Explorer Event Functions
; ( reference to the Event Obj interface: )
; ( https://msdn.microsoft.com/en-us/library/aa703876(v=vs.85).aspx )
;

Func IEEventIE_TitleChange($oEvent)
   Local $MyRef = $oIE.document.getElementById($oEvent)
   ConsoleWrite(VarGetType($MyRef) & @CRLF)
   ConsolePrint("Changed: " & $oEvent & '  New value: ' & $MyRef.Value)
EndFunc   ;==>IEEvent2_TitleChange

Volatile Func IEEvent2_onClick($oEvent)
    ConsolePrint("mouse click: " & $oEvent.clientX & ',' & $oEvent.clientY & '  on ' & $oEvent.srcElement.NodeName & '  id: ' & $oEvent.srcElement.id)
    If $oEvent.srcElement.NodeName = "INPUT" Then
        If $oEvent.srcElement.type = "radio" Or $oEvent.srcElement.type = "checkbox" Then
            If $oEvent.srcElement.checked = True Then
                ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " True")
            Else
                ConsolePrint("name: " & $oEvent.srcElement.name & " id " & $oEvent.srcElement.id & " False")
            EndIf
        EndIf
    EndIf
EndFunc   ;==>IEEvent2_onClick

Volatile Func IEEvent2_onDblClick($oEvent)
    ConsolePrint("mouse DoubleClick: @" & $oEvent.clientX & ',' & $oEvent.clientY)
EndFunc   ;==>IEEvent2_onDblClick

;~ Volatile Func IEEvent2_onMouseMove($oEvent)
;~     ConsolePrint("mouse moved to:" & @TAB & "Xpos = " & $oEvent.clientX & @TAB & "Ypos = " & $oEvent.clientY)
;~ EndFunc   ;==>IEEvent2_onMouseMove

; ===================================
Volatile Func IEEvent_Input_onkeydown($oEvent) ; onChange($oEvent)
    ConsolePrint("KeyCode: " & $oEvent.keyCode)
EndFunc   ;==>IEEvent_Input_onkeydown

Volatile Func IEEvent_Input_onkeypress($oEvent)
    ; Fires when you exit from the input and ONLY IF YOU HAVE CHANGED IT'S CONTENT
    ;                ----                    -------------------------------------
    ConsolePrint('Input content in "First name" field has changed')
EndFunc   ;==>IEEvent_Input_onkeypress
; ===================================

Func ConsolePrint($sMsg)
    Local Const $iMaxLines = 9 ; keep last 9 log lines only
    $sMsg = @HOUR & ':' & @MIN & ':' & @SEC & ':' & @MSEC & @TAB & $sMsg & @CRLF
    $sMsg = StringReplace(GUICtrlRead($g_idGUIEdit) & $sMsg, @CR, @CR)
    If @extended > $iMaxLines Then ; more than $iMaxLines
        $sMsg = StringMid($sMsg, StringInStr($sMsg, @CR, 0, -1 * $iMaxLines) + 2)
    EndIf
    GUICtrlSetData($g_idGUIEdit, $sMsg)
EndFunc   ;==>ConsolePrint

Func _GetHTML()
    ;form html code from: Marc Clifton, 16 Feb 2013, https://www.codeproject.com/Articles/547451/WebBrowser-Element-Events-and-Values
    ;JavaScript from: Marijn Haverbeke (2011), Eloquent JavaScript: a modern introduction to programming. No Starch Press, Inc.
    Local $sHTML = _
            "<!DOCTYPE HTML>" & @CRLF & _
            "<html>" & @CRLF & _
            "<head>" & @CRLF & _
            "<meta http-equiv='X-UA-Compatible' content='IE=edge' />" & @CRLF & _
            "<title>Test</title>" & @CRLF & _
            "</head>" & @CRLF & _
            "<body>" & @CRLF & _
            "<button type='button' id='btnMenu'>=</button>" & @CRLF & _
            "<button type='button' id='btnClose'>X</button>" & @CRLF & _
            "<br>" & @CRLF & _
            "<form>First name: <input id='firstname' type='text' name='firstname'/>" & @CRLF & _
            "<br>" & @CRLF & _
            "Last name: <input id='lastname' type='text' name='lastname'/>" & @CRLF & _
            "<br>" & @CRLF & _
            "Password: <input id='password' type='password' name='pwd'/>" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='radio' id='male' name='sex' value='male'/>Male" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='radio' id='female' name='sex' value='female'/>Female" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='checkbox' id='bike' name='vehicle' value='Bike'/>I have a bike" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='checkbox' id='car' name='vehicle' value='Car'/>I have a car" & @CRLF & _
            "<br>" & @CRLF & _
            "<input type='button' id='ok' value='OK'/><br/>" & @CRLF & _
            "<input type='button' id='cancel' value='Cancel'/>" & @CRLF & _
            "</form>" & @CRLF & _
            "<script type='text/javascript'>" & @CRLF & _
            "var firstname = document.getElementById('firstname');" & @CRLF & _
            "var lastname = document.getElementById('lastname');" & @CRLF & _
            "var password = document.getElementById('password');" & @CRLF & _
            "var male = document.getElementById('male');" & @CRLF & _
            "var female = document.getElementById('female');" & @CRLF & _
            "var bike = document.getElementById('bike');" & @CRLF & _
            "var car = document.getElementById('car');" & @CRLF & _
            "" & @CRLF & _
            "//Marijn Haverbeke (2011), Eloquent JavaScript: a modern introduction to programming. No Starch Press, Inc." & @CRLF & _
            "var output = dom('DIV', {id: 'printOutput'}, dom('H3', null, 'Print output:'));" & @CRLF & _
            "window.onload = document.body.appendChild(output);" & @CRLF & _
            "// print('Hello');" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(firstname, 'change', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "print(event.srcElement.value);" & @CRLF & _
            "document.title = event.srcElement.id;" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(lastname, 'change', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "print(event.srcElement.value);" & @CRLF & _
            "document.title = event.srcElement.id;" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(password, 'change', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "print(event.srcElement.value);" & @CRLF & _
            "document.title = event.srcElement.id;" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(male, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  //ok" & @CRLF & _
            "  print(event.srcElement.outerHTML +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  //Not working (tested with Internet Explorer 7)" & @CRLF & _
            "  //print(event.srcElement.GetAttribute('name'));" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "registerEventHandler(female, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  print(event.srcElement.outerHTML +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "//Returning always true ?" & @CRLF & _
            "registerEventHandler(bike, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  print(event.srcElement.value +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "//Returning always true ?" & @CRLF & _
            "registerEventHandler(car, 'click', function(event) {" & @CRLF & _
            "event = event || window.event;" & @CRLF & _
            "  if (event.srcElement.value = true) {" & @CRLF & _
            "  print(event.srcElement.value +  ' Coordinates: ' + event.clientX +  ' , ' + event.clientY);" & @CRLF & _
            "  //Not working (tested with Internet Explorer 7)" & @CRLF & _
            "  //print(car.GetAttribute('checked'));" & @CRLF & _
            "  }" & @CRLF & _
            "});" & @CRLF & _
            "" & @CRLF & _
            "function registerEventHandler(node, event, handler) {" & @CRLF & _
            "if (typeof node.addEventListener == 'function')" & @CRLF & _
            "node.addEventListener(event, handler, false);" & @CRLF & _
            "else" & @CRLF & _
            "node.attachEvent('on' + event, handler);" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function print() {" & @CRLF & _
            "var result = [];" & @CRLF & _
            "forEach(arguments, function(arg){result.push(String(arg));});" & @CRLF & _
            "output.appendChild(dom('PRE', null, result.join('')));" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function dom(name, attributes, children) {" & @CRLF & _
            "var node = document.createElement(name);" & @CRLF & _
            "if (attributes) {" & @CRLF & _
            "forEachIn(attributes, function(name, value) {" & @CRLF & _
            "node.setAttribute(name, value);" & @CRLF & _
            "});" & @CRLF & _
            "}" & @CRLF & _
            "for (var i = 2; i < arguments.length; i++) {" & @CRLF & _
            "var child = arguments[i];" & @CRLF & _
            "if (typeof child == 'string')" & @CRLF & _
            "child = document.createTextNode(child);" & @CRLF & _
            "node.appendChild(child);" & @CRLF & _
            "}" & @CRLF & _
            "return node;" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function forEachIn(object, action) {" & @CRLF & _
            "for (var property in object) {" & @CRLF & _
            "if (object.hasOwnProperty(property))" & @CRLF & _
            "action(property, object[property]);" & @CRLF & _
            "}" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "function forEach(array, action) {" & @CRLF & _
            "for (var i = 0; i < array.length; i++)" & @CRLF & _
            "action(array[i]);" & @CRLF & _
            "}" & @CRLF & _
            "" & @CRLF & _
            "</script>" & @CRLF & _
            "</body>" & @CRLF & _
            "</html>"
    Return $sHTML
EndFunc   ;==>_GetHTML

 

Updated excel file with similar examples in vba, see end of post:

https://www.autoitscript.com/forum/topic/197979-ie-embedded-capturing-events/?do=findComment&comment=1427391

Edited by robertocm
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...