Sign in to follow this  
Followers 0
ktoya

Embeded IE, click link

3 posts in this topic

Hi,

I have a problem when I want to handle the click event in a embedded IE:

when I click the link the GUI, it will start a real IE to open the link. I need it to be opened in another GUI embedded IE, is it possible? 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well, I was going to suggest that you capture the NewWindow3 event from the browser and open the link yourself, however, I can't seem to cancel the new window from opening.

Maybe somebody can fix this to where the $Cancel = True stops the window from opening... seems like it should, but I must be doing something wrong there.

This code will open any link that is sent to a new window, in the embedded browser itself.  That being said, for some reason it is not cancelling the new window, so you end up with both.  I'm still trying to fix that part.

EDIT: See working code in next post.

Edited by DW1

Share this post


Link to post
Share on other sites

Okay, so Volatile was the key!

Volatile will allow the event function to fire synchronous so we can make our change to Cancel.  Thank you Trancexx for the Volatile keyword!

The following should cancel any new window calls and send the URL that was going to be opened in them to the embedded IE.

#include <GUIConstantsEx.au3>
#include <IE.au3>

Global $oIE = _IECreateEmbedded()
ObjEvent($oIE, "_Evt_", "DWebBrowserEvents2")

$hGUI = GUICreate("Test", 1000, 500)
GUICtrlCreateObj($oIE, 10, 10, 980, 480)
GUISetState(@SW_SHOW)

_IENavigate($oIE, "http://www.w3schools.com/html/tryit.asp?filename=tryhtml_link_target", 0)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Volatile Func _Evt_NewWindow3($ppDisp, ByRef $Cancel, $dwFlags, $bstrUrlContext, $bstrUrl)
    ;Any link being sent to a new window will be canceled and directed back to the embedded IE object
    ConsoleWrite("NewWindow3 attempted to open a new window @ " & $bstrUrl & @CRLF)
    _IENavigate($oIE, $bstrUrl, 0)
    $Cancel = True
EndFunc   ;==>_Evt_NewWindow3

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