Jump to content

How do you close an IE tab?


luger
 Share

Go to solution Solved by luger,

Recommended Posts

Example

#include <IE.au3>

Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
$oIE.Quit

2 tab is opened. But I can not close the second tab? Instead turns off first..

I do not know good english.. :(

Help me.. :(

Edited by luger
Link to comment
Share on other sites

Looks like even though you navigated to the new /forums page

$oIE is still set to autoitscript.com so to close out the new game you need to specify it a variable and tell autoit to close that $var

 

The first tab instead, what should I do in order to close the second tab? Can you give examples of code?.. :)

Link to comment
Share on other sites

So your code snipet is this

Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
$oIE.Quit

The second line $oIE =

is the important part. You've said I want this IE window to be marked as this variable $oIE

so when in your last line you say $oIE.Quit your telling autoit to close that first window you specified to be the variable $oIE

The second window you open DOES NOT have a variable name for you to tell autoit that you want to close it.

You need to tell autoit what the second window is called before you can do anything with it.

Thanks for your time

 

Link to comment
Share on other sites

So your code snipet is this

Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
$oIE.Quit

The second line $oIE =

is the important part. You've said I want this IE window to be marked as this variable $oIE

so when in your last line you say $oIE.Quit your telling autoit to close that first window you specified to be the variable $oIE

The second window you open DOES NOT have a variable name for you to tell autoit that you want to close it.

You need to tell autoit what the second window is called before you can do anything with it.

 

Okey.. :) How'll make it? How do I tell it?

Link to comment
Share on other sites

Your telling autoit that the first window is $oIE and so when you say $oIE.quit it closes the first window

Name the second window something else like $SecondIE or $NotoIE

 

The second variable, I can not come .. How can I get a second variable ?. How can I divide it in half .. :)

Link to comment
Share on other sites

#include <IE.au3>
 
Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
$oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url")
_IEQuit($oIE2)

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

#include <IE.au3>
 
Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
$oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url")
_IEQuit($oIE2)

Thank you.. :) It works .. :) But there is a problem.. :(

dqppNX.png

#include <IE.au3>
 
Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab) ;-->Does not wait for page load

_IELoadWait($oIE) ; --> Does not work.. :(

$oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url") ;--> Warning, $_IEStatus_NoMatch 
_IEQuit($oIE2) ;--> Error, $_IEStatus_InvalidDataType

How do we overcome this? How do we make the wait for pages to load?..

Note: @AutoItVersion ;-->v3.3.12.0 And $ie_version ;-->v8.0

Edited by luger
Link to comment
Share on other sites

  • Moderators

I've messed with this before a couple of years ago.  I had to enum through the IE objects and match it up that way.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

The .Navigate method has no return value, so you must attach to the new IE on your own.

I'd suggest that you put the _IEAttach into a loop, waiting for the new window to be found.  Something like:

While 1
    $oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url")
    If IsObj($oIE2) Then ExitLoop
WEND

 

SmOke_N's method will work too.

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

  • Moderators

Fun times...

#include <IE.au3>

Const $ie_new_in_tab = 0x0800
$oIE = _IECreate("http://www.autoitscript.com")
_IELoadWait($oIE)
__IENavigate($oIE, "http://www.autoitscript.com/forum/", 1, 0x0800)

; [n] = the object to the tab
Global $ga_IETabs = 0
$ga_IETabs = __IE_TabLoadWait($oIE, "http://www.autoitscript.com/forum/", "url")
If @error Then Exit 101

Local $go_NewTab = $ga_IETabs[1] ; I know it's only returning 1
_IEQuit($go_NewTab)


; this will return the objects of the tabs matching type/str and wait if need be
Func __IE_TabLoadWait(ByRef $o_obj, $s_str = "", $s_type = "", $n_msecexpire = 0)

    If Not IsObj($o_obj) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $a_objret = 0
    Local $n_timer = TimerInit()

    While 1
        $a_objret = __IE_GetTabObjs($o_obj, $s_str, $s_type)
        If IsArray($a_objret) Then ExitLoop

        ; return if we set the wait timer and it's reached
        If $n_msecexpire > 0 Then
            If $n_timer >= $n_msecexpire Then
                Return SetError(2, 0, 0)
            EndIf
        EndIf
        Sleep(250)
    WEnd

    If Not IsArray($a_objret) Then
        Return SetError(3, 0, 0)
    EndIf
    
    ; set normal _ieloadwait default
    If $n_msecexpire < 1 Then $n_msecexpire = -1

    For $i = 1 To UBound($a_objret) -  1
        _IELoadWait($a_objret[$i], 0, $n_msecexpire)
    Next
    
    ; this could return multiple if there is more than 1 tab
    ;   with the same url/title for $s_type passed
    Return $a_objret
EndFunc

; returns all the instances of tabs matching type/str criteria
Func __IE_GetTabObjs(ByRef $o_obj, $s_str = "", $s_type = "")

    If Not IsObj($o_obj) Then
        Return SetError(1, 0, 0)
    EndIf

    Local $a_otabs[101], $i_add = 0, $i_next = 1, $o_ieattach
    $s_type = StringLower($s_type)

    While 1
        ; we start at instance 1 and enum as we find more instances
        $o_ieattach = _IEAttach($o_obj, "instance", $i_next + 1)
        If @error = $_IEStatus_NoMatch Or Not IsObj($o_ieattach) Then ExitLoop
        
        ; control array size
        If Mod($i_add + 1, 100) = $i_add Then
            ReDim $a_otabs[$i_add + 101]
        EndIf

        Switch StringLower($s_type)
            Case "url"
                If String(Execute("$o_ieattach.locationurl")) = $s_str Then
                    $i_add += 1
                    $a_otabs[$i_add] = $o_ieattach
                EndIf
            Case "title"
                If WinGetText(String(Execute("$o_ieattach.hwnd"))) = $s_str Then
                    $i_add += 1
                    $a_otabs[$i_add] = $o_ieattach
                EndIf
            Case Else
                $i_add += 1
                $a_otabs[$i_add] = $o_ieattach
        EndSwitch
        $i_next += 1
    WEnd

    If $i_add = 0 Then Return SetError(2, 0, 0)

    ReDim $a_otabs[$i_add + 1]
    $a_otabs[0] = $i_add

    Return $a_otabs
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Solution

The .Navigate method has no return value, so you must attach to the new IE on your own.

I'd suggest that you put the _IEAttach into a loop, waiting for the new window to be found.  Something like:

While 1
    $oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url")
    If IsObj($oIE2) Then ExitLoop
WEND

SmOke_N's method will work too.

Dale

 

Thank you.. :) It works .. :)

Full version:

#include <IE.au3>

Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
While 1
   $oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url") ;--> IE.au3 T3.0-1 Warning from function _IEAttach, $_IESTATUS_NoMatch :)
   If IsObj($oIE2) Then ExitLoop
WEND
_IEQuit($oIE2) ; Or $oIE2.Quit

Full version2:

#include <IE.au3>

Const $ie_new_in_tab=0x0800
$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
While 1
   $oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url") ;--> IE.au3 T3.0-1 Warning from function _IEAttach, $_IESTATUS_NoMatch :)
   If IsObj($oIE2) Then ExitLoop
   WEND
Sleep(500)
Send("^w") ; Tab close.. :)

Full version3-No warnings:

#include <IE.au3>

Const $ie_new_in_tab=0x0800
_IEErrorNotify(0) ;-->No warnings.. :)

$oIE = _IECreate("http://www.autoitscript.com")
$oIE.Navigate("http://www.autoitscript.com/forum/", $ie_new_in_tab)
While 1
   $oIE2 = _IEAttach("http://www.autoitscript.com/forum/", "url")
   If IsObj($oIE2) Then ExitLoop
WEND
$oIE2.Quit
Edited by luger
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...