Jump to content

How to use ie.au3 to intercept link and button clicks?


Recommended Posts

As requested I moved this here from the main ie thread.

Your question is still not very clear to me, but I'll give you some food for thought.

When you use _IEDocWriteHTML, when the function completes IE will parse the HTML and display it just as if it had been a page that was navigated to (there are some cases I've seen, like writing frames, that a refresh must be performed - _IEAction($oIE, "refresh")) -- so you can freely use hyperlinks or any HTML.

So, it appears that your question is really how can your application intercept a click event and then take action based upon that event? You're right, this is not functionality in IE.au3 today (I need to balance simplicity with functionality... there is so much that CAN be done I had to draw a line). You can do it with AutoIt in combination with IE.au3 however.

To capture the event of an object being clicked, you need to use the AutoIt ObjEvent function. There are not a lot of examples of this in the forum, but a search will net you a few (you'll actully find quite a few matches for error handlers, but few for actual event processing).

I'm revisiting this and wanted to discuss it a little more thanks for the responce. Idealy this is what I want to do as since I'm using ie to display data it would be more visually apealing than the option below. However I have to admit I have no idea were to start regarding this.

I'd suggest that you use <BUTTON> element instead of a link (<a href=>) because you are not actually wanting the browser to take action for you after a click, but rather you want to trap and process it.

If your HTML contains the following:

<button id=myButton value=NextChapter>

You could have AutoIt code like the following:

$oMyButton = _IEGetObjByName($oIE, "myButton")
$oEvtMyButton = ($oMyButton, "IEEvent_")

; do some stuff

Func IEEvent_onclick()
    ; take your actions based on the button click in here
EndFunc

Dale

Edit: typos

I think I understand this ok but if I want to have more than one link/button per page whould I simply trap the button info somehow in the IEEvent_onclick function?

One last thing. I think I understand that ie.au3 can get form data and so that is not an issue but and here is the other thing. Should the above method of using buttons and intercepting the clicks also be able to pull the form data and then use it for a search quiery for instance?

Link to comment
Share on other sites

  • Moderators

Well this works for one click:

Read below posts for more information.

#include <IE.au3>

Global _
        $i = 0, _
        $oLinks, _
        $oEvent, _
        $oEvents[1]

; Register the IE.au3 Error Handler
_IEErrorHandlerRegister()

; Create a new browser window and navigate to a webpage
$sURL = "www.google.com"
$oIE = _IECreate($sURL)

; Set up an event sink so that we can trigger on page loads
$oEvent = ObjEvent($oIE.document.parentWindow, "IE_Evt_")

; The inital page load is already done... refresh so that event fires
_IEAction($oIE, "refresh")

; Keep the script running as long as $oIE is a browser object
While WinExists(_IEPropertyGet($oIE, "hwnd"))
    Sleep(10)
WEnd

Func IE_Evt_onload()
    ; Make sure the page is finished loading before we do anything
    _IELoadWait($oIE)
    ; This will keep the normal context menu from displaying
    _IEHeadInsertEventScript($oIE, "document", "oncontextmenu", ";return false")
    $i = 0
    $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        ReDim $oEvents[$i + 1]
        $oEvents[$i] = ObjEvent($oLink, "IE_Evt_")
        $i += 1
    Next
EndFunc   ;==>IE_Evt_onload

Func IE_Evt_onclick()
    $oElement = @COM_EventObj
    ; Copy information from the clicked link object to the clipboard
    ClipPut("Text: " & $oElement.outerText & @CRLF & _
            "URL: " & $oElement.href & @CRLF & _
            "Class: " & $oElement.className & @CRLF & _
            "Color: " & $oElement.currentStyle.color & @CRLF & _
            "Font Family: " & $oElement.currentStyle.fontFamily & @CRLF & _
            "Font Size: " & $oElement.currentStyle.fontSize & @CRLF & _
            "Font Style: " & $oElement.currentStyle.fontStyle & @CRLF & _
            "Font Weight: " & $oElement.currentStyle.fontWeight & @CRLF & _
            "Parent: " & $oElement.parentElement.tagName)
EndFunc   ;==>IE_Evt_onclick

Func IE_Evt_oncontextmenu()
    ; Show a msgbox when you right click on a link object
    MsgBox(0, "", "You right clicked.")
EndFunc   ;==>IE_Evt_oncontextmenu

Func IE_Evt_onmouseover()
    $oElement = @COM_EventObj
    ; Show a tooltip when the mouse is over a link object
    ToolTip("Text: " & $oElement.outerText & @CRLF & _
            "URL: " & $oElement.href & @CRLF & _
            "Class: " & $oElement.className & @CRLF & _
            "Color: " & $oElement.currentStyle.color & @CRLF & _
            "Font Family: " & $oElement.currentStyle.fontFamily & @CRLF & _
            "Font Size: " & $oElement.currentStyle.fontSize & @CRLF & _
            "Font Style: " & $oElement.currentStyle.fontStyle & @CRLF & _
            "Font Weight: " & $oElement.currentStyle.fontWeight & @CRLF & _
            "Parent: " & $oElement.parentElement.tagName)
EndFunc   ;==>IE_Evt_onmouseover

Func IE_Evt_onmouseout()
    ; Get rid of the tooltip when the mouse leaves the object
    ToolTip("")
EndFunc   ;==>IE_Evt_onmouseout

Edit: Updated code

Edited by big_daddy
Link to comment
Share on other sites

You no doubt are aware of this post where I demonstrate some similar constructs...

I don't have time at the moment to try this cose, but I'm curious about the If @COM_EventObj == $oIE Then statement... in my testing all COM variables are equal... have you found different behavior?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • Moderators

You no doubt are aware of this post where I demonstrate some similar constructs...

Correct, I would have never been able to come up with the custom helpfile script without it.

I don't have time at the moment to try this cose, but I'm curious about the If @COM_EventObj == $oIE Then statement... in my testing all COM variables are equal... have you found different behavior?

No, just bad concept. :whistle:

I updated the code with a better concept, but it still doesn't work.

Link to comment
Share on other sites

Correct, I would have never been able to come up with the custom helpfile script without it.

No, just bad concept. :whistle:

I updated the code with a better concept, but it still doesn't work.

Here ya go...

; Set up an event sink so that we can trigger on page loads
$oEvent = ObjEvent($oIE.document.parentWindow, "Evt_")

With the embedded control in the helpfile example you actually get a window object back instead of a browser object. The wondow has the onload event, not the browser.

Good job on the concept... this is interesting.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • Moderators

Here ya go...

; Set up an event sink so that we can trigger on page loads
$oEvent = ObjEvent($oIE.document.parentWindow, "Evt_")

With the embedded control in the helpfile example you actually get a window object back instead of a browser object. The wondow has the onload event, not the browser.

Good job on the concept... this is interesting.

Dale

Dale you are the man! This opens up some great possibilities. I updated the code above with some proof of concept.
Link to comment
Share on other sites

Dale you are the man! This opens up some great possibilities. I updated the code above with some proof of concept.

I would suggest using this code in your idle loop:

While WinExists(_IEPropertyGet($oIE, "hwnd"))
    Sleep(10)
WEnd

instead of the undocumented __IsObjType...

It would be great to expand this for forms and form elements and to actually show the syntax of functions to get references to them... and to have a hotkey to copy the function syntax to the clipboard and and and... :whistle: -- good stuff.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Sorry I got kind of lost com objects and activex are not my cup of tea. Some micrsoft named company created all kinds of garbage code and call it an api.

At any rate I do love the syntax of autoit, php, python, ruby and maybe a few others that I have looked at. I'm the most familliar with autoitand php though.

Having said that what exactly does the above example do? I have spent the last day or so messing with css trying to get submit buttons to emulate regular html links.

If I understant it will intercept a single link on a page?

Link to comment
Share on other sites

Sorry just reread the code. I get it now. It copies the info to the clipboard. Sorry for the stupidity.

One more question: is there a way to controle the right click menu also. I know I can do it through javascript but that is not optimal.

Link to comment
Share on other sites

Here is an issue:

If You try to redirect output to another page ( for instance so that a loading page can be displayed) then you will get errors:

Here is how I changed it:

Func IE_Evt_onclick()   
    $oElement = @COM_EventObj
    _IENavigate ($oIE, "About:Blank")
    ClipPut("Text: " & $oElement.outerText & @CRLF & _
            "URL: " & $oElement.href & @CRLF & _
            "Class: " & $oElement.className & @CRLF & _
            "Color: " & $oElement.currentStyle.color & @CRLF & _
            "Font Family: " & $oElement.currentStyle.fontFamily & @CRLF & _
            "Font Size: " & $oElement.currentStyle.fontSize & @CRLF & _
            "Font Style: " & $oElement.currentStyle.fontStyle & @CRLF & _
            "Font Weight: " & $oElement.currentStyle.fontWeight & @CRLF & _
            "Parent: " & $oElement.parentElement.tagName)
EndFunc ;==>IE_Evt_onclick

here is the error

--> COM Error Encountered in ie-testing.au3
----> $IEComErrorScriptline = 
----> $IEComErrorNumberHex = 00000000
----> $IEComErrorNumber = 
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 

--> COM Error Encountered in ie-testing.au3
----> $IEComErrorScriptline = 
----> $IEComErrorNumberHex = 00000000
----> $IEComErrorNumber = 
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 

--> COM Error Encountered in ie-testing.au3
----> $IEComErrorScriptline = 
----> $IEComErrorNumberHex = 00000000
----> $IEComErrorNumber = 
----> $IEComErrorWinDescription = 
----> $IEComErrorDescription = 
----> $IEComErrorSource = 
----> $IEComErrorHelpFile = 
----> $IEComErrorHelpContext = 
----> $IEComErrorLastDllError = 

C:\Program Files\AutoIt3\beta\Include\IE.au3 (3874) : ==> Variable must be of type "Object".: 
$IEComErrorScriptline = $oIEErrorHandler.scriptline 
$IEComErrorScriptline = $oIEErrorHandler^ ERROR

If I change the function to this:

Func IE_Evt_onclick()   
    $oElement = @COM_EventObj

    ClipPut("Text: " & $oElement.outerText & @CRLF & _
            "URL: " & $oElement.href & @CRLF & _
            "Class: " & $oElement.className & @CRLF & _
            "Color: " & $oElement.currentStyle.color & @CRLF & _
            "Font Family: " & $oElement.currentStyle.fontFamily & @CRLF & _
            "Font Size: " & $oElement.currentStyle.fontSize & @CRLF & _
            "Font Style: " & $oElement.currentStyle.fontStyle & @CRLF & _
            "Font Weight: " & $oElement.currentStyle.fontWeight & @CRLF & _
            "Parent: " & $oElement.parentElement.tagName)
    _IENavigate ($oIE, "About:Blank")
EndFunc ;==>IE_Evt_onclick

you still get this error:

C:\Program Files\AutoIt3\beta\Include\IE.au3 (3874) : ==> Variable must be of type "Object".: 
$IEComErrorScriptline = $oIEErrorHandler.scriptline 
$IEComErrorScriptline = $oIEErrorHandler^ ERROR
Edited by webmedic
Link to comment
Share on other sites

  • Moderators

Sorry just reread the code. I get it now. It copies the info to the clipboard. Sorry for the stupidity.

One more question: is there a way to controle the right click menu also. I know I can do it through javascript but that is not optimal.

See the above code for an example of how to do this.
Link to comment
Share on other sites

Thanks for that. I should have worded it better I want to limit the menu so they can cut copy paste but not use the normal system context menu.

Now I have one more issue. I worked this into my gui that I have been playing with and it does not work with an embeded ie activex control.

Here is the gui code.

#include <GUIConstants.au3>
#include <IE.au3>

Opt("TrayIconDebug", True)
Opt("OnExitFunc", "onExit");"OnAutoItExit" called

Global _
        $i = 0, _
        $oLinks, _
        $oEvent, _
        $oEvents[1]

; Set a COM Error handler -- only one can be active at a time (see helpfile)
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()

; Create a simple GUI for our output
GUICreate("beams of light", 780, 600, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$GUI_Input_URL = GUICtrlCreateInput("Enter a Search here..", 10, 10, 700, 20)
$GUI_Button_Go = GUICtrlCreateButton("Go!", 720, 10, 50, 20)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 760, 520)
;$GUI_Progress      = GUICtrlCreateProgress (            10, 470 , 600 , 20 )
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 560, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 560, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 560, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 330, 560, 100, 30)

GUISetState()    ;Show GUI
; This works no matter what and does not conflict at all with theeven handler below.
; Turning it on or off makes no difference.
; Commented it out to make it easier to see the event handlers from below.
;$SinkObject=ObjEvent($oIE,"IE_Evt_","DWebBrowserEvents")

; 1st method does not work. It would appear as though when the browser is embbeded that
; it does not collect document.parentWindow events
_IENavigate ($oIE, @ScriptDir & "\readertest.html")
$oEvent = ObjEvent($oIE.document.parentWindow, "IE_Evt_")
; I'm stabbing in the dark here but these dont work either.
;$oEvent = ObjEvent($oIE.document.this.window, "IE_Evt_")
;$oEvent = ObjEvent($oIE.document.thisWindow, "IE_Evt_")
_IEAction($oIE, "refresh")

_ReduceMemory()

; Waiting for user to close the window
While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            _IENavigate ($oIE, @ScriptDir & "\readertest.html")
            _ReduceMemory()
        Case $msg = $GUI_Button_Back
            $oIE.GoBack
            _ReduceMemory()
        Case $msg = $GUI_Button_Forward
            $oIE.GoForward
            _ReduceMemory()
        Case $msg = $GUI_Button_Stop
            $oIE.Stop
            _ReduceMemory()
        Case $msg = $GUI_Input_URL Or $msg = $GUI_Button_Go
            _IENavigate ($oIE, @ScriptDir & "\readertest.html?" & GUICtrlRead( $GUI_Input_URL ))
            _ReduceMemory()
    EndSelect
    Sleep(15)
WEnd
onExit()

Func onExit()
    $oIE="" 
    GUIDelete()
    Exit
EndFunc  ;==>onExit 

Func IE_Evt_onload()   
    $i = 0
    _IELoadWait($oIE)
    $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        ReDim $oEvents[$i + 1]
        $oEvents[$i] = ObjEvent($oLink, "IE_Evt_")
        $i += 1
    Next
    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = Getting links" & @CR) 
EndFunc  ;==>IE_Evt_onload

Func IE_Evt_onclick()   
    $oElement = @COM_EventObj
    ClipPut("Text: " & $oElement.outerText & @CRLF & _
            "URL: " & $oElement.href & @CRLF & _
            "Class: " & $oElement.className & @CRLF & _
            "Color: " & $oElement.currentStyle.color & @CRLF & _
            "Font Family: " & $oElement.currentStyle.fontFamily & @CRLF & _
            "Font Size: " & $oElement.currentStyle.fontSize & @CRLF & _
            "Font Style: " & $oElement.currentStyle.fontStyle & @CRLF & _
            "Font Weight: " & $oElement.currentStyle.fontWeight & @CRLF & _
            "Parent: " & $oElement.parentElement.tagName)
EndFunc  ;==>IE_Evt_onclick

Func IE_Evt_onmouseover()
    $oElement = @COM_EventObj
    ToolTip("Text: " & $oElement.outerText & @CRLF & _
            "URL: " & $oElement.href & @CRLF & _
            "Class: " & $oElement.className & @CRLF & _
            "Color: " & $oElement.currentStyle.color & @CRLF & _
            "Font Family: " & $oElement.currentStyle.fontFamily & @CRLF & _
            "Font Size: " & $oElement.currentStyle.fontSize & @CRLF & _
            "Font Style: " & $oElement.currentStyle.fontStyle & @CRLF & _
            "Font Weight: " & $oElement.currentStyle.fontWeight & @CRLF & _
            "Parent: " & $oElement.parentElement.tagName)
    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = onmouseover event" & @CR) 
EndFunc
       
Func IE_Evt_onmouseout()
    ToolTip("")
EndFunc 

Func IE_Evt_ProgressChange($Progress,$ProgressMax)

    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = ProgressChange event" & @CR)  

EndFunc

Func IE_Evt_StatusTextChange($Text)

    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = StatusTextChange event" & @CR)    
    
EndFunc

Func IE_Evt_PropertyChange( $szProperty)

    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = PropertyChange event" & @CR)  
    
EndFunc

Func IE_Evt_DownloadBegin()

    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = DownloadBegin event" & @CR)   

EndFunc

Func IE_Evt_DownloadComplete()

    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = DownloadComplete event" & @CR)    

EndFunc

Func IE_Evt_NavigateComplete2($oWebBrowser,$URL)  

    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = NavigateComplete2 event" & @CR)   

EndFunc

Func _ReduceMemory()
    Local $ai_GetCurrentProcessId = DllCall('kernel32.dll', 'int', 'GetCurrentProcessId')
    Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ai_GetCurrentProcessId[0])
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Return $ai_Return[0]
EndFunc  ;==>_ReduceMemory

Func _FileReadAll($File)
    Local $OpenFile
;Local $File
    Local $ReadAll
    $OpenFile = FileOpen($File, 0)
    If $OpenFile = -1 Then Return -1
    $ReadAll = FileRead($OpenFile, FileGetSize($File))
    FileClose($OpenFile)
    Return $ReadAll
EndFunc  ;==>_FileReadAll

Func _SaveFile($File, $Text)
    $OpenFile = FileOpen($File, 2)
    If $OpenFile = -1 Then
        FileClose($OpenFile)
        Return -1
    EndIf
    FileWrite($OpenFile, $Text)
    FileClose($OpenFile)
EndFunc  ;==>_SaveFile

the attached zip includes my css html and everything else I'm using to test as it is to much to post here.readertest.zip

Link to comment
Share on other sites

"does not work" is not very descriptive. What is it you expect to happen and what happens instead? What have you done to try to troubleshoot it?

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Yes if you look at the code it is commented.

I have tried document.thisWindow, document.self, etc. Trying to get it to grab the links.

If you use this as an embedded activex component then it will not grgab any events from parentwindow.

Whats worse is that the code example above (not mine) will through nothing but errors after a few clicks the autoit process will die and the ie window will still be running but not doing what it is supposed to do.

I spent the better part of last night troubleshooting and even tried your code for using buttons but that throughs errors. Thanks.

Link to comment
Share on other sites

OK. You posted quite a bit of code, so your comments did not stand out for me. A quick note to point that out would have saved that embarassment :-)

It appears that your trouble is caused by the document and window being recreated after a refresh. Take out the refresh and you should see some event get processed until the first page reload.

You'll need to change your logic so that your event routines get destroyed and reconnected each time a "new" document gets loaded.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Ok also I was messing with other things also and found that. If I load the file into a string and then display it using document write that about:blank as prepended to all the links which kind of messes things up also.

Any ideas or hints on that one. I can post some code later today but want to try out your suggestion fisrt.

thanks.

Edited by webmedic
Link to comment
Share on other sites

Sorry, I'm not following you and don't understand what question you are trying to ask.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

I'm not sureho to make it much clearer instead of a lik looking like somepage.html it looks like about:blanksomepage.html. This gets addded to every singlew link on the page.

#include <GUIConstants.au3>
#include <IE.au3>

Opt("TrayIconDebug", True)
Opt("OnExitFunc", "onExit");"OnAutoItExit" called

Global _
        $i = 0, _
        $oLinks, _
        $oEvent, _
        $oEvents[1]

; Set a COM Error handler -- only one can be active at a time (see helpfile)
_IEErrorHandlerRegister ()

$oIE = _IECreateEmbedded ()
$tIE = _IECreateEmbedded ()
; Create a simple GUI for our output
GUICreate("Reader", 780, 600, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$GUI_Input_URL = GUICtrlCreateInput("Enter a Search here..", 10, 10, 700, 20)
$GUI_Button_Go = GUICtrlCreateButton("Go!", 720, 10, 50, 20)
$GUIActiveXt = GUICtrlCreateObj($tIE, 10, 40, 760, 520)
GUICtrlSetState(-1, $GUI_HIDE)

$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 760, 520)
;$GUI_Progress      = GUICtrlCreateProgress (            10, 470 , 600 , 20 )
$GUI_Button_Back = GUICtrlCreateButton("Back", 10, 560, 100, 30)
$GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 560, 100, 30)
$GUI_Button_Home = GUICtrlCreateButton("Home", 230, 560, 100, 30)
$GUI_Button_Stop = GUICtrlCreateButton("Stop", 330, 560, 100, 30)


GUISetState()    ;Show GUI

_IENavigate ($tIE, "about:")
_IENavigate ($oIE, "about:")

$reader = _FileReadAll(@ScriptDir & "\readertest.html")
_IEDocWriteHTML ($oIE, $reader)
_IELoadWait($oIE)
; This will keep the normal context menu from displaying
_IEHeadInsertEventScript($oIE, "document", "oncontextmenu", ";return false")
$i = 0
$oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    ReDim $oEvents[$i + 1]
    $oEvents[$i] = ObjEvent($oLink, "IE_Evt_")
    $i += 1
Next
_ReduceMemory()

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $GUI_Button_Home
            GUISetState(@SW_DISABLE, $oIE)
            $reader = _GetTemplate(@ScriptDir & "\readertest.html")
            _IEDocWriteHTML ($oIE, $reader)
            _IELoadWait($oIE)
            _IEHeadInsertEventScript($oIE, "document", "oncontextmenu", ";return false")
            $i = 0
            $oLinks = _IELinkGetCollection($oIE)
            For $oLink In $oLinks
                ReDim $oEvents[$i + 1]
                $oEvents[$i] = ObjEvent($oLink, "IE_Evt_")
                $i += 1
            Next
            GUISetState(@SW_ENABLE, $oIE)
            _ReduceMemory()
        Case $msg = $GUI_Button_Back
            $oIE.GoBack
            _ReduceMemory()
        Case $msg = $GUI_Button_Forward
            $oIE.GoForward
            _ReduceMemory()
        Case $msg = $GUI_Button_Stop
            $oIE.Stop
            _ReduceMemory()
        Case $msg = $GUI_Input_URL Or $msg = $GUI_Button_Go
            _IENavigate ($oIE, @ScriptDir & "\readertest.html?" & GUICtrlRead( $GUI_Input_URL ))
            _ReduceMemory()
    EndSelect
    Sleep(15)
WEnd
onExit()

Func onExit()
    $oIE="" 
    GUIDelete()
    Exit
EndFunc  ;==>onExit 

Func IE_Evt_onclick()   
    $oElement = @COM_EventObj
    GUISetState(@SW_DISABLE, $oIE)
    GUICtrlSetState($GUIActiveXt, $GUI_SHOW)
    GUICtrlSetState($GUIActiveX, $GUI_HIDE)
    $reader = _GetTemplate(@ScriptDir & "\readertest.html")
    $reader = _ParseTemplate($reader, "<rdr_testing>", $oElement.href)
    _IEDocWriteHTML ($oIE, $reader)
    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = " & $oElement.href & @CR)
    _IELoadWait($oIE)
   ; This will keep the normal context menu from displaying
    _IEHeadInsertEventScript($oIE, "document", "oncontextmenu", ";return false")
    $i = 0
    $oLinks = _IELinkGetCollection($oIE)
    For $oLink In $oLinks
        ReDim $oEvents[$i + 1]
        $oEvents[$i] = ObjEvent($oLink, "IE_Evt_")
        $i += 1
    Next
    GUISetState(@SW_ENABLE, $oIE)
    GUICtrlSetState($GUIActiveX, $GUI_SHOW)
    GUICtrlSetState($GUIActiveXt, $GUI_HIDE)
    _ReduceMemory()
EndFunc  ;==>IE_Evt_onclick

Func IE_Evt_onmouseover()
    $oElement = @COM_EventObj
;   $recvRequest = StringSplit($oElement.href, "?") 
    ConsoleWrite("@@debug(" & @ScriptLineNumber & ") : @working = onmouseover "  & $oElement.href & @CR)    
EndFunc

Func _ReduceMemory()
    DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
EndFunc  ;==>_ReduceMemory

Func _GetTemplate($File)
    Local $oTempl
    $oTempl = _FileReadAll($File)
    Return $oTempl
EndFunc  ;==>_GetTemplate

Func _ParseTemplate($oTempl, $oRepl, $oCont)
    $oTempl = StringReplace($oTempl, $oRepl, $oCont)
    Return $oTempl
EndFunc  ;==>_ParseTemplate

Func _FileReadAll($File)
    Local $OpenFile
;Local $File
    Local $ReadAll
    $OpenFile = FileOpen($File, 4)
    If $OpenFile = -1 Then Return -1
    $ReadAll = FileRead($OpenFile, FileGetSize($File))
    FileClose($OpenFile)
    Return $ReadAll
EndFunc  ;==>_FileReadAll

Func _SaveFile($File, $Text)
    $OpenFile = FileOpen($File, 2)
    If $OpenFile = -1 Then
        FileClose($OpenFile)
        Return -1
    EndIf
    FileWrite($OpenFile, $Text)
    FileClose($OpenFile)
EndFunc  ;==>_SaveFile

this is how the code works. I have completely bypassed those issues though by creating a second ie object and hiding it. Then I show it while I'm doping my work and when finished I hide it again. Kind of a messyt work around but it works.

This code is completely working now. onload events dont work at all. So I used just the link click events. This works very well. After the link is clicked switch to the second ie object. Parse the bad url with about:blank in it. Get the data ready for display then load it into the the first ie object and then hide the second ie object again and show the first.

Now for some reason if you show a page through document.write like this it wont load external links and stuff. So dont use external javascript or css files and you wont be able to load pictures either. But for my purposes it works ok.

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...