Alodar 0 Posted July 30, 2010 So, I thought I could write a function to create a new tab for those times when I needed multiple tabs open for things. I wanted to return an object so that I could then manipulate it. When I check that it's an object inside the function, it's fine. when I return it outside of the function however, it's NOT and object....? What's going on? expandcollapse popup#include <IE.au3> $oIE = _IECreate("www.google.com", 0, 1, 0, 0) _IELoadWait($oIE) $oIE2 = _IECreateTab($oIE, "about:blank") If IsObj($oIE2) Then MsgBox(0, "test", "It's an object") EndIf ;========================================== Func _IECreateTab($o_object, $s_Url, $f_wait = 1) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidDataType") Return SetError($_IEStatus_InvalidDataType, 1, 0) EndIf ; If Not __IEIsObjType($o_object, "documentContainer") Then __IEErrorNotify("Error", "_IENavigate", "$_IEStatus_InvalidObjectType") Return SetError($_IEStatus_InvalidObjectType, 1, 0) EndIf ; $o_object.navigate2($s_Url, 2048) Sleep(500) ;~ without this it crashes every time because it doesn't create it fast enough Local $o_object2 = _IEAttach($s_Url, "url") ;~ attach the tab to the secondary object If Not IsObj($o_object2) Then ;Make sure it's an object __IEErrorNotify("Error", "_IECreateEmbedded", "", "WebBrowser Object Creation Failed") Return SetError($_IEStatus_GeneralError, 0, 0) EndIf If $f_wait Then _IELoadWait($o_object2) Return SetError(@error, 0, -1) EndIf Return SetError($_IEStatus_Success, 0, $o_object2) EndFunc Share this post Link to post Share on other sites
DaleHohm 65 Posted July 30, 2010 Because you are returning -1 instead of $o_object2 If $f_wait Then _IELoadWait($o_object2) Return SetError(@error, 0, -1) EndIf Doh! Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curlMSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object modelAutomate input type=file (Related)Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better?IE.au3 issues with Vista - WorkaroundsSciTe 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
Alodar 0 Posted July 30, 2010 (edited) Because you are returning -1 instead of $o_object2 If $f_wait Then _IELoadWait($o_object2) Return SetError(@error, 0, -1) EndIf Doh! Damnitsomuch! Thanks DaleHohm. Also, in my first post I should have given you credit for basically writing the function since all I did was copy and paste most of the pieces from _IEAttach() and _IECreate() in order to make it. Your IE.au3 thing is my most heavily used udf; so thanks for this. Any chance of there being a function such as this in future releases? Edited July 30, 2010 by Alodar Share this post Link to post Share on other sites
DaleHohm 65 Posted July 30, 2010 Yes, there is a good chance of a similar function being added. I had actually been trying to figure out a logical way to augment _IENavigate to accomodate this, but adding a new function may in fact be the way to go. In what I have boilerplated so far, I use a different scheme to attach to the new tab that does not require an arbitrary Sleep: $s_RandomUrl = "about:blank-" & Random(1000000, 9999999, 1) $o_IE = _IECreate($sRandomUrl) Local $i_timer = TimerInit() While Not _IEAttach($sRandom, "url") If Int(TimerDiff($i_timer) / 1000) > 10 Then _ __IEErrorNotify("Error", "_IECreateTab", "$_IEStatus_GeneralError", "Tab creation failed. Waited 10 seconds.") Return SetError($_IEStatus_GeneralError, 0, 0) Sleep(100) WEnd $o_IE = _IEAttach($sRandom, "url") _IENavigate($o_IE, $s_Url) You may want to fit it into what you are doing. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curlMSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object modelAutomate input type=file (Related)Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better?IE.au3 issues with Vista - WorkaroundsSciTe 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
Alodar 0 Posted July 30, 2010 (edited) That's interesting, you don't use the Navigate2? I'm running IE7, and IECreate will always create a new instance for me, not a new tab. In fact, the tryattach portion of IECreate always fails on my runs, giving me an error of NoMatch. Or maybe I misunderstood your statement and this was more of an example of the timeout function for the sleep rather than the new tab creation. Edited July 30, 2010 by Alodar Share this post Link to post Share on other sites
DaleHohm 65 Posted July 30, 2010 Sorry, the _IECreate should have been the call to Navigate2 method... the sameple was supposed to be both, but the crux of what I was trying to give you was the timer loop and the trick of using about:blank-randomNumber as the initial URL. You probably also want to set _IEErrorNotify to False as well to avoid console messages with the _IEAttach Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curlMSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object modelAutomate input type=file (Related)Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better?IE.au3 issues with Vista - WorkaroundsSciTe 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