Jump to content

Embedded IE - open links in default browser


Iczer
 Share

Recommended Posts

I need make IE open links from html page (loaded in embedded IE in my GUI) in windows-default browser (firefox, etc...). But since I cannot prevent embedded IE from actually reacting to click in _IEEvent_BeforeNavigate2() function, anything in vain... 

So question - is there a way to do it?

 

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


Example()

Func Example()


    $hGUI = GUICreate("Example", 888,555)

    Global $oIE = _IECreateEmbedded ()
    $oIE_ctrl = GUICtrlCreateObj($oIE, 8, 8, 872, 539)
    $hIEFrame = GUICtrlGetHandle($oIE_ctrl)
    GUISetState(@SW_SHOW)

    ; Error monitoring. This will trap all COM errors while alive.
    ; This particular object is declared as local, meaning after the function returns it will not exist.
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

    ; Navigate somewhere
    $oIE.navigate("http://www.google.com/")
    ; Check for errors while loading
    If @error Then
        $oIE.Quit()
        Return
    EndIf

    ; Wait for page to load
    While 1
        If $oIE.readyState = "complete" Or $oIE.readyState = 4 Then ExitLoop
        Sleep(10)
    WEnd


    ; Custom sink object
    Local $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")

    ; Wait for user to click any link to to open this link in default browser (firefox etc.)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch

    WEnd

    #forceref $oErrorHandler, $oIEEvents
EndFunc   ;==>Example

; BeforeNavigate2 method definition
Func _IEEvent_BeforeNavigate2($oIEpDisp, $sIEURL, $iIEFlags, $sIETargetFrameName, $sIEPostData, $iIEHeaders, $bIECancel)
    ConsoleWrite("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!--BeforeNavigate2 fired--!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & _
            "$oIEpDisp = " & $oIEpDisp() & "  -  " & ObjName($oIEpDisp) & @CRLF & _ ; e.g. default property and name for the object
            "$sIEURL = " & $sIEURL & @CRLF & _
            "$iIEFlags = " & $iIEFlags & @CRLF & _
            "$sIETargetFrameName = " & $sIETargetFrameName & @CRLF & _
            "$sIEPostData = " & $sIEPostData & @CRLF & _
            "$iIEHeaders = " & $iIEHeaders & @CRLF & _
            "$bIECancel = " & $bIECancel & @CRLF & _
            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " & @CRLF & @CRLF)
EndFunc   ;==>_IEEvent_BeforeNavigate2

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

Func _IEEvent_OnQuit ()
    $oIE = 0
    Exit
EndFunc

 

Link to comment
Share on other sites

you could add this just after page end loading (after the 'Wait for page to load' loop):

Local $oLinks = _IELinkGetCollection($oIE)
For $oLink In $oLinks
    $oLink.target = "_blank"
Next

p.s.

If you set the target attribute to "_blank", the link will open in a new browser window or a new tab.

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

It make browser open new window, but it's still same IE - the only solution is ProcessClose() it in _IEEvent_NewWindow3(), but flashing is visible

on other hand for some reason i cant catch mouseclick event in embedded IE frame (in WM_NOTIFY)  - is there a solution for it?

Link to comment
Share on other sites

Thanks! It seems what i need! (i was blind :sweating:)

Main purpose - is to keep embedded IE in sandbox so it wont interfere with settings in my script, so I do not need(and know how) to install Adblock-like plugins in IE6, and also to make possible for IE6 navigate to any HTTPS sites with fancy SSL/TLS algorithms via external means (like cURL)

Link to comment
Share on other sites

  • 2 years later...

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