Sign in to follow this  
Followers 0
4Eyes

Problem reading URL in other than 1st tab of IE 8

3 posts in this topic

#1 ·  Posted (edited)

Folks,

What I want to do is determine the url for each tab in IE 7/8 and I suppose 9. I've found a way to get this via polling

(post #4 here: ),

but that's not as elegant as being advised when one has changed and what it was changed to. I can get this for the 1st tab, by using the DWebBrowserEvents (actually DWebBrowserEvents2) and NavigateComplete2 member but I can't get any others.

It seems there's a few people working on similar issues to mine, but I'm trying something different. The code below is a slightly mod'ed version of the code in the 'COM events' section in the helpfile. It uses DWebBrowserEvents2. I've commented out some of the other func's as their output clutters the display in terms of what I'm looking for.

I've also tried to create 2 objects, the 2nd using $oIE2 = ObjCreate("InternetExplorer.Application.2") but $oIE2 is an Interger32 not an Object so I suspect the 2nd tab is not associated with "InternetExplorer.Application.2".

Can anybody please advise?

Thanks,

4Eyes

#cs
This script is in the help file. see 'ObjCreate'. In the 'COM events' section there is a hyperlink: 'Click "here" to view the complete script.'
Trimmed it somewhat to only see NavigateComplete events.
With IE 8, sees events from 1st tab only. Other tabs are different windows so how to get NavigateComplete2 event for them?
#ce

; Example script, showing the usage of COM Event functions.
; Requires at least AutoIt beta version 3.1.1.104 !
;
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp

; We use a very simple GUI to show the results of our Events.
#include "GUIConstantsEx.au3"

$GUIMain=GUICreate              ( "Event Test",       600,500 )
$GUIEdit=GUICtrlCreateEdit      ( "Test Log:" & @CRLF,  10, 20, 580, 400)
$GUIProg=GUICtrlCreateProgress  (                       10,  5, 580,  10)
$GUIExit=GUICtrlCreateButton    ( " Close ",          250, 450, 80,  30)
GUISetState ()               ;Show GUI

; We prepare the Internet Explorer as our test subject
$oIE = ObjCreate("InternetExplorer.Application.1")
With $oIE
    .Visible=1
    .Top = (@DesktopHeight - 400) / 2
    .Height = 600           ; Make it a bit smaller than our GUI.
    .Width = 800
    .Silent = 1             ; Don't show IE's dialog boxes
    $IEWnd = HWnd(.hWnd)    ; Remember the Window, in case user decides to close it
EndWith

; We choose for a specific Internet Explorer interface 'DWebBrowserEvents' because the IE is subject
; to modifications by e.g. Visual Studio and Adobe Acrobat Reader. If you have IE-plugins installed,
; AutoIt might not be able to find the correct interface automatically.

; According to 'http://msdn.microsoft.com/en-us/library/aa768309(VS.85).aspx', use of DWebBrowserEvents is obsolete. Using DWebBrowserEvents2 instead

;$EventObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents2")
If @error Then
   Msgbox(0,"AutoIt COM Test", _
    "ObjEvent: Can't use event interface 'DWebBrowserEvents2'. Error code: " & hex(@error,8))
   Exit
EndIf

; Now starting to load an example Web page.
$URL = "http://www.google.com.au/"
;$oIE.Navigate2($URL, 2048)             ; Open in new tab... interestly NavigateComplete2 does not see this
$oIE.Navigate2($URL)                    ; Open in default tab
Sleep(1000)                             ; Give it some time to load the web page

GUISwitch($GUIMain)                     ; Switch back to our GUI in case IE stealed the focus

; Waiting for user to close the GUI.
While 1
   $msg = GUIGetMsg()
   If $msg = $GUI_EVENT_CLOSE Or $msg = $GUIExit Then ExitLoop
Wend

$EventObject.Stop                       ; Tell IE we don't want to receive events.
$EventObject = 0                        ; Kill the Event Object
If WinExists($IEWnd) Then $oIE.Quit     ; Close IE Window - hmmm.... $IEWnd is never set so how can it be tested?
$oIE.Quit                               ; Really close IE window, else they mount up.

$oIE = 0                                ; Remove IE from memory (not really necessary).

GUIDelete ()                            ; Remove GUI

Exit                                    ; End of our Demo.

;****************************

; According to http://msdn.microsoft.com/en-us/library/aa768334(v=VS.85).aspx
; pDisp An object that evaluates to the top-level or frame WebBrowser object corresponding to the event.
; URL A string expression that evaluates to the URL, UNC file name, or PIDL that was navigated to. Note that this URL can be different from the URL that the browser was told to navigate to.
;    One reason is that this URL is the canonicalized and qualified URL; for example, if an application specified a URL of "www.microsoft.com" in a call to the Navigate or Navigate2 method, the URL passed by DocumentComplete will be "http://www.microsoft.com/". Also, if the server has redirected the browser to a different URL, the redirected URL will be reflected here.

Func IEEvent_NavigateComplete2($pDisp, $URL)

    ;   Note: the declaration is different from the one on MSDN.
    GUICtrlSetData($GUIEdit, "IE has finished loading URL: " & $URL & @CRLF  , "append")

EndFunc

;****************************

Func IEEvent_($EventName)
; This is an optional event function to catch non-defined events.
; The parameter contains the name of the event being called.

 ;   GUICtrlSetData($GUIEdit, "Uncatched event: " & $EventName & @CRLF  , "append")

EndFunc

;****************************

#cs
; This doesn't fire for other than primary tab either

Func IEEvent_DocumentComplete()

    GUICtrlSetData ( $GUIEdit, "IE has finished a navigation operation" & @CRLF  , "append" )

EndFunc

; A few Internet Explorer Event Functions
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/webbrowser.asp

Func IEEvent_BeforeNavigate($URL, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)
;   Note: the declaration is different from the one on MSDN.
    GUICtrlSetData ( $GUIEdit, "BeforeNavigate: " & $URL & " Flags: " & $Flags & " tgframe: " & $TargetFrameName & " Postdat: " & $PostData & " Hdrs: " & $Headers & " canc: " & $Cancel  & @CRLF  , "append" )
EndFunc

Func IEEvent_ProgressChange($Progress,$ProgressMax)
    If $ProgressMax > 0 Then
        GUICtrlSetData($GUIProg, ($Progress * 100) / $ProgressMax )
    EndIf
EndFunc

Func IEEvent_StatusTextChange($Text)
    GUICtrlSetData ( $GUIEdit, "IE Status text changed to: " & $Text & @CRLF  , "append" )
EndFunc

Func IEEvent_PropertyChange( $szProperty)
    GUICtrlSetData ( $GUIEdit, "IE Changed the value of the property: " & $szProperty & @CRLF  , "append" )
EndFunc

Func IEEvent_DownloadComplete()
    GUICtrlSetData ( $GUIEdit, "IE has finished a navigation operation" & @CRLF  , "append" )
EndFunc
#ce
Edited by 4Eyes

Share this post


Link to post
Share on other sites



Try this:

Dim $aIE[1]
$aIE[0] = 0
$i = 1
While 1
    $oIE = _IEAttach ("", "instance", $i)
    If @error = $_IEStatus_NoMatch Then ExitLoop
    ReDim $aIE[$i + 1]
    $aIE[$i] = $oIE
    $aIE[0] = $i
    $i += 1
    ConsoleWrite($oIE.LocationURL&@CRLF)
WEn

Maybe modify it a bit...

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Juvigy,

We have a winner! Yep, needed a couple of mods, like appending the d to the WEnd and including IE.au3 :x

The point it gives the url's for all tabs which is ultimately what I really wanted. I need to poll but I can live with that, although to be notified when the URL changes (via NavigateComplete) would be far better.

BTW, it reports on multiple simultaneous IE browsers too.

[Edit] I must have been looking at this stuff too long now. I see I already replied about this in another thread.

Thanks so much for your efforts.

4Eyes

Edited by 4Eyes

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