Sign in to follow this  
Followers 0
JohnMC

GUI Embedded IE and $oIE.GoBack issue

6 posts in this topic

ive created a gui that uses an embeded IE object, im having an issue with the goback function as shown in the help file:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Example()

; Simple example: Embedding an Internet Explorer Object inside an AutoIt GUI
;
; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp
Func Example()
    Local $[color="#ffffff"]oIE[/color], $GUIActiveX, $GUI_Button_Back, $GUI_Button_Forward
    Local $GUI_Button_Home, $GUI_Button_Stop, $msg
    
    $[color="#ffffff"]oIE[/color] = ObjCreate("Shell.Explorer.2")

    ; Create a simple GUI for our output
    GUICreate("Embedded Web control Test", 640, 580, (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN))
    $GUIActiveX = GUICtrlCreateObj ($[color="#ffffff"]oIE[/color], 10, 40, 600, 360)
    $GUI_Button_Back = GUICtrlCreateButton("Back", 10, 420, 100, 30)
    $GUI_Button_Forward = GUICtrlCreateButton("Forward", 120, 420, 100, 30)
    $GUI_Button_Home = GUICtrlCreateButton("Home", 230, 420, 100, 30)
    $GUI_Button_Stop = GUICtrlCreateButton("Stop", 330, 420, 100, 30)

    GUISetState()     ;Show GUI

    $[color="#ffffff"]oIE[/color].navigate("http://www.autoitscript.com")

    ; Waiting for user to close the window
    While 1
        $msg = GUIGetMsg()

        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $GUI_Button_Home
                $[color="#ffffff"]oIE[/color].navigate("http://www.autoitscript.com")
            Case $msg = $GUI_Button_Back
                [color="#ffffff"]$[color="#ffffff"]oIE[/color].GoBack[/color]
            Case $msg = $GUI_Button_Forward
                $[color="#ffffff"]oIE[/color].GoForward
            Case $msg = $GUI_Button_Stop
                $[color="#ffffff"]oIE[/color].Stop
        EndSelect
        
    WEnd

    GUIDelete()
EndFunc   ;==>Example

My issue is that in both the help file example and in my GUI, calling "GoBack" will cause an error if you have nothing to go back to.

The requested action with this object has failed.

Ive tried to prevent this with the if statement below but a crafty user can still cause the error by pressing the button a second time before the first goback action has completed:

If $oIE.LocationURL<>$URL_START Then $oIE.GoBack

any ideas? you can reproduce this problem by running the example for GUICtrlCreateObj and pressing the back button right after the example launches

Share this post


Link to post
Share on other sites



The example for _IECreateEmbedded does exactly what you are trying to do.

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 Dale!

I wanted to figure out why this works so i sorted over the UDF and it apears this is the magical line (Modified for my use):

$objError = ObjEvent("AutoIt.Error", "_ErrorHandlerFunction")

It appears that the UDF doesn't deal with the problem it just deals with the error, thats ok with me, and i assume registering that event will work for all autoit errors so thats kinda cool.

thanks again

Share this post


Link to post
Share on other sites

It is not a "problem". Some errors are expected - and this is one of them. You need to learn to trap such situations and react accordingly.

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

Just to update anyone who ran into the same thing i did: the method of capturing the error instead of avoiding it is probably the best way of doing this but i wanted to try and come up with an alternative so here it is:

In this method you would create a different "start" url and "home" url, the start url will have any unique string at the end of it as long as it wont interfere with the page loading.

$URL_HOME="http://www.autoitscript.com"
$URL_HOME_START=$URL_HOME&"/#START"

Your initial navigation of the embedded IE will be with $URL_HOME_START and then any home operation would navigate it to $URL_HOME

Then before you perform your back operation you check to make sure the current page isnt $URL_HOME_START. The trick is to also make sure the browser isnt busy to avoid issues with multiple back operations becoming queued and resulting in the error.

If $oIE.LocationURL<>$URL_SI_START AND NOT $oIE.Busy Then $oIE.GoBack

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