Jump to content

IE Obj NewWindow3


Recommended Posts

http://www.autoitscript.com/forum/index.php?showtopic=55282

On that topic is an example for "intercept" IE's events

I tried several times to intercept the event "NewWindow3", but Internet Explorer crashes off until I kill the script with the task manager

This is the script that I've made. I can not understand where I've wrong.

#include <IE.au3>

Local $oIE = _IECreate()
ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2"); Assign events to UDFs starting with IEEvent_
_IEPropertySet($oIE,'visible',1)
_IENavigate($oIE,'www.google.com')

While 1
    Sleep(50)
WEnd

Func IEEvent_NewWindow3 ($ppDisp, $Cancel, $dwFlags, $bstrUrlContext, $bstrUrl)
ConsoleWrite('New window to: '&$bstrUrlContext&@LF)
EndFunc

Here I found the information needed for the event "NewWindow3":

http://msdn.microsoft.com/en-us/library/aa768337.aspx

Edited by Sbarabau
Link to comment
Share on other sites

The first two parameters of that event are ByRef, and AutoIt doesn't have that capability. I doesn't work for me, but I don't get errors either. Maybe hitting the ByRef parameters keeps the event handler from being called?

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I can't explain why you don't see the NewWindow3 event... an expanded example below shows that other events are bing trapped but not this one. PSaltyDS makes an important point about byRef, but it should not prevent us from seeing the event, only from being able to cancel it.

You may want to work up an example in vbscript and see if it behaves differently.

Dale

oops, forgot code:

#include <IE.au3>

$oIE = _IECreate("http://www.w3schools.com/html/html_links.asp")
$oSink = ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2"); Assign events to UDFs starting with IEEvent_

While 1
    Sleep(50)
WEnd

Func IEEvent_NewWindow3 ($ppDisp, $Cancel, $dwFlags, $bstrUrlContext, $bstrUrl)
ConsoleWrite('New window to: '&$bstrUrlContext&@LF)
EndFunc

Func IEEvent_ ($event)
ConsoleWrite('Event: '&$event&@LF)
EndFunc
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

Link to comment
Share on other sites

Hmm... some Googling turned this up:

In a VB6 application I use the WebBrowser Control (shdocvw.dll). I need to

check the URL as a new window is being opened. The only way is to get the

URL when the NewWindow3 event is fired. When I try to select the NewWindow3

event in the IDE, a popup message told me: "Function or interface marked as restricted, or the function uses an

Automation type not supported in Visual Basic".

Interface marked as restricted...?

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I can't explain why you don't see the NewWindow3 event... an expanded example below shows that other events are bing trapped but not this one. PSaltyDS makes an important point about byRef, but it should not prevent us from seeing the event, only from being able to cancel it.

You may want to work up an example in vbscript and see if it behaves differently.

Dale

oops, forgot code:

#include <IE.au3>

$oIE = _IECreate("http://www.w3schools.com/html/html_links.asp")
$oSink = ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2"); Assign events to UDFs starting with IEEvent_

While 1
    Sleep(50)
WEnd

Func IEEvent_NewWindow3 ($ppDisp, $Cancel, $dwFlags, $bstrUrlContext, $bstrUrl)
ConsoleWrite('New window to: '&$bstrUrlContext&@LF)
EndFunc

Func IEEvent_ ($event)
ConsoleWrite('Event: '&$event&@LF)
EndFunc

I can't program in VB

I can't also see the NewWindow and NewWindow2 events.

I can't tell if it is a bug in AutoIt or a problem in the variables of the NewWindow3 event.

How can I resolve this problem?

Link to comment
Share on other sites

So far, it looks to me like Microsoft doesn't want that event available without at least some kind of elevated privileges.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

#RequireAdmin is enough?

If not, how can I do this?

Don't know, haven't found anything explicit from MSDN about the problem.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Note from above.... I suggested reproducing in VBScript, not VB. If you can code in AutoIt, a few minutes with a reference guide for VBScript on the internet should make you profient enough to replicate the code in VBScript.

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 tried so, but the event NewWindow3 is not detected.

Set IEobject = WScript.CreateObject("InternetExplorer.Application","IEobject_")
IEobject.Visible = True
IEobject.Navigate2 "http://www.google.it"

Do While IEobject.Visible
    WScript.Sleep 500
Loop

Sub IEobject_BeforeNavigate2(pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel)
    Wscript.Echo "Going to:", URL
    Cancel = True
End Sub

Sub IEobject_NewWindow3(ppDisp, ByRef Cancel, bstrUrlContext, bstrUrl)
    Wscript.Echo "New window:", bstrUrl
    Cancel = True
End Sub
Edited by Sbarabau
Link to comment
Share on other sites

I tried so, but the event NewWindow3 is not detected.

Set IEobject = WScript.CreateObject("InternetExplorer.Application","IEobject_")
IEobject.Visible = True
IEobject.Navigate2 "http://www.google.it"

Do While IEobject.Visible
    WScript.Sleep 500
Loop

Sub IEobject_BeforeNavigate2(pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel)
    Wscript.Echo "Going to:", URL
    Cancel = True
End Sub

Sub IEobject_NewWindow3(ppDisp, ByRef Cancel, bstrUrlContext, bstrUrl)
    Wscript.Echo "New window:", bstrUrl
    Cancel = True
End Sub
VBScript can use ByRef in the event, but all variables are type VARIANT, so IE won't recognize changes to Cancel because it doesn't want a variant returned. As Dale said before, this should only keep you from using Cancel in VBScript, and not prevent the event from firing.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

ok, but how can I then receive the event NewWindow3 in AutoIt?

Well, there's the catch: The same way you would in VBScript -- if it worked in VBScript -- which it doesn't.

:mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

The point of trying it in VBScript is that if it doesn't work there, you can take the issue to the Microsoft Community discussion boards or log a problem report with Microsoft (and if it doesn't work in VBScript, it is not an AutoIt problem). There, you will find hundreds if not thousands of people who may be able to help you, in addition to the developers who have access to the source code and having a vested interest in making it work as documented (here there are are only a handful).

Unless you choose an alternate approach as Juvigy suggests, pushing harder here will no be fruitful.

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

It is best to think of something else to use instead of this NewWindow3 event.

What exactly do you want to do in your script?

I created a small multitab browser based on IE

When you click an external link then creates a new window, but belonging to IE

I would then intercept the event NewWindow3 to prevent the opening of the new window and direct it in a new tab in my browser

The point of trying it in VBScript is that if it doesn't work there, you can take the issue to the Microsoft Community discussion boards or log a problem report with Microsoft (and if it doesn't work in VBScript, it is not an AutoIt problem). There, you will find hundreds if not thousands of people who may be able to help you, in addition to the developers who have access to the source code and having a vested interest in making it work as documented (here there are are only a handful).

Unless you choose an alternate approach as Juvigy suggests, pushing harder here will no be fruitful.

Dale

The solution to communicate this problem to Microsoft is feasible.

How can I do this?

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