Brickoneer Posted September 7, 2008 Posted September 7, 2008 (edited) Here's the idea: I have a embedded IE object that I want to use as a menu. I want to be able to capture the link clicks from this embedded IE so I can process them via autoit and manipulate my GUI accordingly. I got the event capturing working.... (see example below) #include<ie.au3> $oIE = _IECreate("www.google.com") $oEvt = ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") while 1 sleep(10) wend Func IEEvent_BeforeNavigate2($notsurewhatthisis,$url,$TargetFrameName,$PostData,$Headers, $Cancel) ;;;;; consolewrite($url&@CR) EndFunc ... but now I'm stuck. I can capture the event, but how can I then cancel the navigation so my embedded IE doesn't change? I see the "$cancel" variable passed in the event, but it cannot be passed byref, so I cannot internally cancel the navigation. Any ideas? Thanks, Brick Edited September 7, 2008 by Brickoneer
Brickoneer Posted September 8, 2008 Author Posted September 8, 2008 I did some more reading and found an old thread from '05 that confirmed that the event cancel cannot be passed byref, so thats out. Can you guys think of possible workarounds? The content of the embedded IE will probably be home-brewed html pasted in there with _IEdocwritehtml... I'm not sure if that will help or not. Thanks for your help! Brick
Linux Posted September 8, 2008 Posted September 8, 2008 did you try _IEAction($oie,"stop") to cancel the navigation? Kind regards, Linux You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Brickoneer Posted September 8, 2008 Author Posted September 8, 2008 Thanks for your input! Thats an incredibly simple solution I missed. It works beautifully for regular navigation as I can stop navigation before it actually finds and loads the page... unfortunately it does not work with home-brewed html. The links are not actual complete website urls (see example below) and are thus returned almost immediately...before _IEaction can stop it. I've prepared a little example below to show it not working... commenting out the line that pastes the home-brewed html in there and it mostly works... otherwise it does not. expandcollapse popup#include <GUIConstants.au3> #include <GUIConstantsEx.au3> #include <IE.au3> #include <WindowsConstants.au3> _IEErrorHandlerRegister () $oIE = _IECreateEmbedded () GUICreate("Embedded Web control Test", 640, 580, _ (@DesktopWidth - 640) / 2, (@DesktopHeight - 580) / 2, _ $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $GUIActiveX = GUICtrlCreateObj($oIE, 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", 340, 420, 100, 30) GUISetState() _IENavigate ($oIE, "http://www.autoitscript.com") _IEDocWriteHTML($oIE,'<html><body><a href="index.php?showtopic=80001">click here</a></body></html>') $oEvt = ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_Button_Home _IENavigate ($oIE, "http://www.autoitscript.com") Case $msg = $GUI_Button_Back _IEAction ($oIE, "back") Case $msg = $GUI_Button_Forward _IEAction ($oIE, "forward") Case $msg = $GUI_Button_Stop _IEAction ($oIE, "stop") EndSelect WEnd GUIDelete() Exit Func IEEvent_BeforeNavigate2($notsurewhatthisis,$url,$TargetFrameName,$PostData,$Headers,$Cancel) _IEAction($oIE,"stop") ConsoleWrite($url&@CR) EndFunc It seems as though objevent does not allow me to intercept events but only be notified when they are sent. If I were intercepting, placing a sleep command in the handling function would actually cause the navigation to stop until I returned it... and it would also allow me to set the $cancel parameter. Is there a way to intercept the event messages instead? thanks for your help. Brick
Linux Posted September 9, 2008 Posted September 9, 2008 remember that the autoit its waiting for the page to fully load before continue. you can change that adding a 0 as parameter like this: Case $msg = $GUI_Button_Home _IENavigate ($oIE, "http://www.autoitscript.com",0) Also, I think this line: $oEvt = ObjEvent($oIE,"IEEvent_","DWebBrowserEvents2") should be before this one: GUISetState() You can help! Donate to AutoIt! or, visit ClimatePREDICTION.netMy posts:Travian Bot Example (100+ servers) BETAHow to Host you code/app for free! (unlimited team number) (Public or Private)"Sir, we're surrounded!" "Excellent. We can attack in any direction!"
Brickoneer Posted September 10, 2008 Author Posted September 10, 2008 I have added the changes you suggested and it still does not manage to stop it when the link leads to something that does not actually exist. (The actual navigate event is fired by the user clicking on the embedded IE, not from the _IEnavigate function) For example, if you run my example in post #4 and click on the "here" link in the embedded browser, the link does not actually exist and so it returns before my _ieaction can fire. Thanks for your help, Brick
DaleHohm Posted September 10, 2008 Posted September 10, 2008 You'll nee to do the cancel in Javascript instead of in AutoIt. See _IEHeadWriteEventScript. You should be able to cancel the navigation there and still be able to trap and process the event in AutoIt. 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now