Jump to content

IE / Com Object helps!


Recommended Posts

Howdy,

Just starting to learn about Coms and Objects etc...

Simple script but i don't know why it wouldn't cancel the second navigation (toally usless script, i'm just learning). The first Nav to Autoit is stopped but not to warcraft movies.

$oIE=ObjCreate("InternetExplorer.Application.1")
$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")

; Do some browsing activities
$oIE.Visible=1
$oIE.Navigate( "http://www.AutoItScript.com" )
sleep(4000)
$oIE.Navigate( "http://www.warcraftmovies.com" )


Func IEEvent_BeforeNavigate()
$oIE.stop
EndFunc

sleep(30000)

Thanks in advance,

S

They call me MrRegExpMan

Link to comment
Share on other sites

Use the event DownloadBegin():

$oIE=ObjCreate("InternetExplorer.Application.1")
$SinkObject=ObjEvent($oIE,"IEEvent_","DWebBrowserEvents")

; Do some browsing activities
$oIE.Visible=1
$oIE.Navigate( "http://www.AutoItScript.com" )
sleep(4000)
$oIE.Navigate( "http://www.warcraftmovies.com" )
sleep(4000)

Func IEEvent_DownloadBegin()
    $oIE.stop
EndFunc

Beforenavigate event occurs before the unloading of the website and to work you have to introduce a delay. For example:

Func IEEvent_BeforeNavigate($URL, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)
sleep(100)
$oIE.stop
EndFunc

Func IEEvent_BeforeNavigate($URL, $Flags, $TargetFrameName, $PostData, $Headers, $Cancel)
    Do
        Sleep(10)
    Until $oIE.readystate=3
    $oIE.stop
EndFunc

Really the page load is canceled by the parameter $cancel=true, but this is not right because is reference by reference (byref), and Autoit does not do well.

Saludos.

(moderador de www.autoit.es)

Link to comment
Share on other sites

Unfortunately, AutoIt processes COM events asynchronously. You cannot cancel because you are not really in the event processing loop, you are just being notified of the event. To do this, you must inject javascript into the page itself.

If you haven't already, suggest you look at IE.au3 (IE Management in the helpfile UDFs). _IEHeadInsertEventScript can be used to do what I suggest above.

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

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