Sign in to follow this  
Followers 0
dickjones007

closing all ie tabs except one

8 posts in this topic

#1 ·  Posted (edited)

as the title says

can this be done in any way

something like:

if ietab_title="chainlink" then

close all other tabs

endif

or

maybe list through all the tabs and close the ones that are not called "chainlink"

there is an option on right clicking tab that says "close other tabs". can i use this maybe with some autoit action?

and also i would like to activate this script if number of ietabs greater than 1

Edited by dickjones

Share this post


Link to post
Share on other sites



no one?

Share this post


Link to post
Share on other sites

Are you trying to block all websites with the exception of one website?

I have just recently wrote a program for this.. i am happy to post the code. It may give you a starting point.

Share this post


Link to post
Share on other sites

i think that might be helpful

please post the code

but actually all i simply want is to close all tabs except one which is defined by class and instance or anything that will make it unique.

Share this post


Link to post
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=close.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstants.au3>
#Include <File.au3>
#Include <Array.au3>
#include <Misc.au3>
#include <IE.au3>
;*************************************************************************************************************************************************************************
; Version Information
;*************************************************************************************************************************************************************************
; Version 1.2
;*************************************************************************************************************************************************************************
; System Tray Options
;*************************************************************************************************************************************************************************
TraySetIcon(1) ; Creates/Enables a tray icon for the program
TraySetClick(0) ;Stops the tray icon from being clicked on
TraySetToolTip("v1.2") ;When the mouse hovers over the tray icon it displays the text
;*************************************************************************************************************************************************************************
; Variables and Constants Declerations
;*************************************************************************************************************************************************************************
dim $blocked
dim $i
dim $i2
dim $call = 0
dim $refresh_timer = 0
dim $aIE
;dim const $blocklistlocation = "Barnts01programs$programsblock list.txt" ; Writes the location of the keyword file to memory
;dim const $TabClosePromptTitle = FileOpen("Barnts01programs$programstab close prompt title.txt") ;sets the location and opens the file for the string for the tab close prompt window title
dim const $blocklistlocation = ".block list.txt" ; Writes the location of the keyword file to memory
dim const $TabClosePromptTitle = FileOpen(".tab close prompt title.txt") ;sets the location and opens the file for the string for the tab close prompt window title
dim const $TabClosePromptTitleDataCitrix = FileReadLine($TabClosePromptTitle,1) ;gets the tab close prompt window title data (string) from the file - line 1
dim const $TabClosePromptTitleDataIE = FileReadLine($TabClosePromptTitle,2) ;gets the tab close prompt window title data (string) from the file - line 2
;*************************************************************************************************************************************************************************
; Load the list of keywords from the block list.txt file to memory (array)
;*************************************************************************************************************************************************************************
_FileReadToArray($blocklistlocation,$blocked) ;Reads the block list text file to memory (array)
;*************************************************************************************************************************************************************************
; Functions
;*************************************************************************************************************************************************************************

Func _Check_Tab_Close() ; This function checks if the internet explorer multiple tab close window is present. If it is present it clicks the close all button
AutoItSetOption("WinTitleMatchMode", 3) ; Used so that when WinExists below is used it searches exactly for the mentioned text only
If WinExists($TabClosePromptTitleDataCitrix) or WinExists($TabClosePromptTitleDataIE) Then ; Checks to see if a window exists with the mentioned text
  Send("{ENTER}") ;Presses (sends) the Enter/Return key
EndIf
Sleep(2000) ;Pauses the program for 2 seconds i.e. keeps the message on screen for that length of time
SplashOff() ; Turns off the on screen message created above
$call = 0 ; Sets the $call variable back to 0 .. see _Win_Close function for variable being set to 1
EndFunc

Func _Win_Close() ; Used to check the IE window URL(s) (single or multi-tab) against a list. If a match is found the IE window is closed.
Dim $aIE[1] ; Creates a space in memory for an array
$aIE[0] = 0 ; Sets the number of elements in the array to 0
$i = 1

While 1 ; starts a loop for collecting the URL(s) of IE
    $oIE = _IEAttach ("", "instance", $i)
    If @error = $_IEStatus_NoMatch Then ExitLoop
    ReDim $aIE[$i + 1]
    $aIE[$i] = _IEPropertyGet($oIE, "locationurl")
    $aIE[0] = $i
    $i += 1
WEnd ; ends the loop
_ArrayDisplay($aIE)
AutoItSetOption("WinTitleMatchMode", 2) ;Sets the searching options for WinClose to search the windows title (set to find X anywhere in string)
; Checks the array $aIE populated from the first above While statement agasint the $blocked array (block list entries) and closes IE if a match is found
For $i = 1 To (UBound($aIE) - 1)
For $i2 = 1 To (UBound($blocked) - 1)
  If StringInStr($aIE[$i],$blocked[$i2]) <> 0 Then
  SplashTextOn("Website Blocker","WEBSITE BLOCKED" & @CRLF & @CRLF & "Access to this site is prohibited!",400,100,-1,-1,33,"",15,900) ; creates a message on screen
  WinClose("[Class:IEFrame]") ;Closes any windows with any of the keywords contained within block list.txt in the windows title
  dim $call = 1 ; sets the $call variable to 1, this is used to see if _Check_Tab_Close function needs to be called
  EndIf
Next
Next
if $call = 1 then ; Checks if $call variable is equal to 1 i.e. check if the _Check_Tab_Close function needs to be called
call ("_Check_Tab_Close") ;Calls the function _Check_Tab_Close
Endif

EndFunc

Func _Refresh_Block_List()
_FileReadToArray($blocklistlocation,$blocked) ;Reads the block list text file to memory (array)
$refresh_timer = 0 ;Sets the timer varaible back to 0 so that the re-counting process can start again
EndFunc
;*************************************************************************************************************************************************************************
; Program Loop (Program in effect starts here)
;*************************************************************************************************************************************************************************
While 1 ;creates an infinite loop
If WinExists("[Class:IEFrame]") Then
call ("_Win_Close") ;call the function _Win_Close
Endif
Sleep(1000) ;Pauses the program for 1 second - Used so it does not cause CPU to max out at 100%
$refresh_timer +=1 ;Adds one to the value of the varaibale every time the while loop runs (runs every second) therefore the timer counts up in seconds
If $refresh_timer = 1800 Then    ; When the timer gets to 1800 seconds (30 minutes) then the function for refreshing the block list is called
    Call ("_Refresh_Block_List") ; Calls the function _Refresh_Block_List to refresh the block list file
EndIf
WEnd

1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thats the latest code i have on my pc.. the finished article (not much different) is at work.

Code posted above. The main things that i think you will want are in there is

While 1 ; starts a loop for collecting the URL(s) of IE
    $oIE = _IEAttach ("", "instance", $i)
    If @error = $_IEStatus_NoMatch Then ExitLoop
    ReDim $aIE[$i + 1]
    $aIE[$i] = _IEPropertyGet($oIE, "locationurl")
    $aIE[0] = $i
    $i += 1
WEnd ; ends the loop

In the autoit help file look for _ieAttach() function and look at example 5 (code below). This would be a good way i think of determining how many tabs you have open.. therefore you could say if the number returned is greater than 1 then close all tabs except the first one.

; *******************************************************
; Example 5 - Create an array of object references to all current browser instances
;              The first array element will contain the number of instances found
; *******************************************************
;
#include <IE.au3>
Dim $aIE[1]
$aIE[0] = 0
$i = 1
While 1
    $oIE = _IEAttach ("", "instance", $i)
    If @error = $_IEStatus_NoMatch Then ExitLoop
    ReDim $aIE[$i + 1]
    $aIE[$i] = $oIE
    $aIE[0] = $i
    $i += 1
WEnd
MsgBox(0, "Browsers Found", "Number of browser instances in the array: " & $aIE[0])

I guess your program is basically being used to limit the number of internet explorer tabs to 1 as there is no built in function in IE to limit the ammount of tabs open at any one time? is that correct?

Edited by pilky1986
1 person likes this

Share this post


Link to post
Share on other sites

thnx

i'll see what i can use

Share this post


Link to post
Share on other sites

thnx

i'll see what i can use

When you have finished it would be interesting to see your code and the outcome.

Happy to help and good luck!

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