Sign in to follow this  
Followers 0
Nick Hance

IE popup blocking

6 posts in this topic

Hey folks, great forum you've got here. I've gotten used to the forum even though the search kind of sucks. It's answered a lot of my questions, but I haven't been able to find this one anywhere here or on the web.

I'm using an OLE object of InternetExplorer.Application to browse and parse webpages for content. It's been working great and lets my script handle a lot of the crappy webpages with broken or malformed HTML. However, I've noticed that it still renders the pages completely including dynamic content such as sounds or movies and popup windows. I want my script to operate with the IE object completely hidden and this is just no good.

I've tracked it down to be able to catch the events sent from the IE object, but I'm unable to cancel the load of the window before it displays. Anyone have any ideas about this?

Here's my code:

; Internet Explorer Instance
$o_IE = ObjCreate("InternetExplorer.Application")


$o_IE.Visible = false
$o_IE.Silent = True
$oEvt = ObjEvent($o_IE, "events_")

Func events_NewWindow($url, $cancel=true, $winname=False)
; The values coming in to this are not the same as spec'd on MSDN. 
; I'm only expecting an object and a boolean, but it sends me a url, a boolean, and a window handle.
    ConsoleWrite("@@" & $url & ";" & $cancel & ";" & $winname & @CR)
    $cancel = true; Does nothing
    return TRUE
EndFunc

; TESTING
$o_IE.navigate("http://www.popuptest.com/popuptest1.html")

Here's the output:

@@http://www.popuptest.com/popup1.html;0;_[361]_pop1
@@http://www.popuptest.com/popup2.html;0;_[363]_No__Name:1
@@http://www.popuptest.com/popup3.html;0;_[365]_
@@http://www.popuptest.com/popup4.html;0;_[367]_No__Name:2
@@http://www.popuptest.com/popup5.html;0;_[369]_No__Name:3
@@http://www.popuptest.com/popup6.html;0;_[371]_No__Name:4

I have no idea how to get this thing to stop these windows from loading. Ideally, I want to get the HTML without even rendering it, but I'm quite attached to being able to rely on the getElementByName() function to parse HTML tags with the attributes in arbitrary order.

If I can't stop the popup window, is there anything I can do that will parse the HTML into a DOM(?) object so I can pull tags as needed that doesn't render the code for display?

Share this post


Link to post
Share on other sites



BUMP!

Am I asking in the wrong forum.. or just impatient? :P

Share this post


Link to post
Share on other sites

BUMP!

Am I asking in the wrong forum.. or just impatient? :P

have you checked out dale's ie.au3? you could probably use it to assign new ie windows, and then handle them the way that you want, beginning with sending a 'stop' command as soon as they're detected. I remember a long time ago, july/august ish someone getting help developing a similar concept. i think in that case they just went with using a WinList() to determine current windows, then a WinClose() to close new windows with a string in the title like "Internet Explorer". and welcome to the forums!

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I believe the trouble you are haing is because $cancel would need to be passed ByRef. Unfortunately, a limitation in the AutoIt implementation of COM event handling prevents this. You'll actually find some references to this in the Bug Forum because passing values intot hte Event routines ByRef was causing an unhandled exception in AutoIt. The fix for this was throwing a syntax error with the ByRef value. There is no workaround to this that I have yet found.

I'm curious how you figured out that the parameters being passed in the NewWindow event were not as documented? Did you find a discussion of this somewhere? Using your example, I don't see a window handle being passed, but rather that funky name field. If you had a handle you could use WinClose to kill it before it appeared (you'd probably need to use the HWND function to make it usabel by AutoIt however).

There are other ways of getting page source (_INetGetSource and HTTPRequest), but they do not give you the functionality of parsing with the DOM.

The only other thing that I've found is the .returnValue property of the window.event object (available in IE5 and later). The documentation of this makes it appear taht setting it to False will prevent the default action of the event routine that you are processing... in this case preventing the Newwindow. I have not been able to get it to affect anything at this point -- but I am worried that I simply have event hierarchy/syntax issues. It may still be worth looking into.

Unfortunately, because of the ByRef limitation, the easy way is not an option. Please let me know if you make any headway.

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 for the replies, unfortunately I've tried both suggestions without any luck.

It appears that the newWindow event is called before the window is created, so it doesn't have access to the new window in the window list.

I've set the return value to false with no help, and here's the documentation for what is expected in event_NewWindow()

http://msdn.microsoft.com/workshop/browser...s/newwindow.asp

If there's no other way to do this, I'll release it with the bug in it. I really didn't want to do that, but I don't have the time available to implement a DOM parser.

Thanks again for your help,

Nick

Share this post


Link to post
Share on other sites

Thanks for the update.

I knew the documented parameters of Newwindow... I was wondering how you figured out that it was returning something different and if you had found a discussion of it anywhere.

The .returnValue I was speaking of can be found here -- one reference I found implied that it provided different results than the function return value, but this may not be the case.

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

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