Sign in to follow this  
Followers 0
plastix

IE Events Processing

7 posts in this topic

Hi all,

Been looking into IE events. I have an HTML page that is embedded into an Autoit GUI using the standard IE COM UDFs etc (_IECreateEmbedded() etc)

As an afterthought, I wondered whether it would be possible to usefully capture IE events for the embedded IE object... There are 3 links to local files - clicking on these opens the File Download dialog - but this would be nicer if it could intercept the event,and then directly open the relevant file via RUN() etc (I used to use a program by 6bytes which essentially embedded IE inot its form, but hooked some macro commands to add functionality to the page ie <href = "macro:exepath\">Open local folder</a> - the program would capturethe HREF info, see the included macro: command and execute its own code here...)

I can capture the FileDownload event using:

$IEevents=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2")
Func IEEvent_FileDownload()
 Msgbox(0,"","DL")
EndFunc

...but I can't work out if it is possible to capture any useful information (ie what file is being downloaded etc). The FileDownload() only uses a boolean cancel variable.

Similarly, the DownloadBegin() event of DWebBrowserEvents2 will fire with all links, but again I am unsure if it is possible to capture any useable information ie the called link etc...

Anybody have any pointers / resource links regarding this? Much appreciated as ever.

Share this post


Link to post
Share on other sites



First, there is an architectural issue with AutoIt COM that may foil your plan: AutoIt takes event delivery, but it handles it asynchronously. You should think of AutoIt as being "notified" of the events rather than being in the event processing flow as you are with Javascript in the browser. I.E. you may get notified of the download event after the download box has already appeared and you will have no way to process a Cancel with a return value.

To do what you are hoping you will really probably need to inject Javascript into the page and possibly rewrite some of the existing Javascript. This can be accomplished pretty easily with the new _IEDoc* functions if the most recent release.

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

Share this post


Link to post
Share on other sites

Thanks DaleHohm.

I would imagine that an embedded IE object is restricted by the same security restrictions that any other webpage is subject to. I wrote the webpage that is displayed, so don't actually have to modify it via AutoIt to insert the onclick etc events into the page. The onclick event will trigger a javascript function appropriately, but this, as far as I know, cannot in itself trigger an AutoIt function... I was interested in potentially triggering AutoIt functions from a webpage... If there is a security-permitted javascript function that might do this, then this is what I am looking for.

Possibly a worst-case scenario is to have the javascript popup an alert() with macro code thatis 'seen' by the parent window - which immediately closes the messagebox and executes the code - but that is 'nasty'.

Thinking laterally, could contain a hidden DIV in the page that the parent window reads using _IEBodyReadHTML - the DIV content could be modified to include a label etc containing the relevant AutoIt macro to execute... again, 'dirty' - but possible (assuming the updated content via javascript is available to _IEBodyReadHTML etc...

I'll tinker...

Share this post


Link to post
Share on other sites

The restrictions I was talking about are not security related.

You CAN invoke AutoIt functions using these events. The Download event may not be a good one to start with however.

Try an onclick event for a form element, button or DIV (DIV is probably easiest if you are comfortable with it). The the function you identify with ObjEvent will be passed an object variable that references the object that triggered the event, so you can differentiate the object either by looking at some of its properties or by checking to see if it is equal to a known object variable.

Make sense?

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

Share this post


Link to post
Share on other sites

Thanks DaleHohm again,

i kind of follow, but not sure how to communicate or trap this in AutoIt.

in the interim, I tried out the hidden DIV option - it's 'dirty' but seems to work. I'd love towork along your guidelines though... if you could provide some code snippets when you have the time I would really appreciate it.

For the 'dirty' method, see the attached files below. :whistle:

IE_feedback.html

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

OK, here you go... start your HTML first, then run the au3...

Here's the au3:

#include <IE.au3>

$oIE = _IEAttach("IE Feedback")

$oB1 = _IEGetObjByName($oIE, "macro1")
$oB2 = _IEGetObjByName($oIE, "macro2")

$oSink1 = ObjEvent($oB1, "B1_")
$oSink2 = ObjEvent($oB2, "B2_")

While 1
    Sleep(100)
WEnd

Func B1_onclick()
    MsgBox(0, "B1", "Button 1 clicked")
EndFunc

Func B2_onclick()
    MsgBox(0, "B2", "Button 2 clicked")
EndFunc

here's your html rewritten:

<html>
<head>
<title>IE Feedback</title>
<style type="text/css">
    .autoit {display:none;}
    .blather {font-size:30px}
</style>
</head>

<body>
<div id="feedback" class="autoit">NOTHING</div>
<center>
    <font class="blather">AutoIt Feedback Test</font><br><br>
<button id='macro1'>MACRO 1</button>
<button id='macro2'>MACRO 2</button>
</body>
</html>

Dale

Edit: simplified code...

Edited by DaleHohm

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

Share this post


Link to post
Share on other sites

Thanks as ever DaleHohm

I'll try that out soon. I see what you meant nowregarding implementationetc. Really appreciate the effort. Thanks again :whistle:

Share this post


Link to post
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
Sign in to follow this  
Followers 0