IE COM get active tab

Get help with using AutoHotkey and its commands and hotkeys
euras
Posts: 404
Joined: 05 Nov 2015, 12:56

IE COM get active tab

20 Apr 2017, 02:44

How to get an active IE tab if there is 2 or more tabs With the same name? It's easy to get one With uniq name, but how about the same name? If I use the code bellow, it Works if there is only one Tab With that name, but if there is 2 Service Tabs, then the code doesn't work (I need that it Works on the active "Service" tab.

Code: Select all

pwb.Visible := True
pwb := IEGet("Service")
Loop{
    sleep 100
	one := pwb.document.getElementById("contentIFrame0").contentDocument.getElementById("IFRAME_EditTask").contentDocument.getElementsByTagName("DIV")[48].innerText
    if (one <> "some text"){
        pwb := IEGet("Service")
        one := pwb.document.getElementById("contentIFrame0").contentDocument.getElementById("IFRAME_EditTask").contentDocument.getElementsByTagName("DIV")[48].innerText
        sleep 100
    }
}until (one = "some text")
msgbox %one%
Return

IEGet(Name="")        ;Retrieve pointer to existing IE window/tab
{
    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
        Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
        : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
    For pwb in ComObjCreate( "Shell.Application" ).Windows
        If ( pwb.LocationName = Name ) && InStr( pwb.FullName, "iexplore.exe" )
            Return pwb
} ;written by Jethrow
User avatar
Xeo786
Posts: 238
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: IE COM get active tab

21 Apr 2017, 04:56

"When there is no gravity, there is absolute vacuum" -Game changer theory
euras
Posts: 404
Joined: 05 Nov 2015, 12:56

Re: IE COM get active tab

21 Apr 2017, 05:38

how it should help me? there is tips for catching an active IE or creating a New one if there is no old one. In my scenario there is allready 2 tabs in IE With the same Title and I searching ways to show the code witch tab the code should take in that scenario (the active one).
User avatar
Xeo786
Posts: 238
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: IE COM get active tab

21 Apr 2017, 08:33

euras wrote:
how it should help me? there is tips for catching an active IE or creating a New one if there is no old one. In my scenario there is allready 2 tabs in IE With the same Title and I searching ways to show the code witch tab the code should take in that scenario (the active one).
WB := IEGET() gona work for active window .... at least working for me just give it a try ... ;)
"When there is no gravity, there is absolute vacuum" -Game changer theory
euras
Posts: 404
Joined: 05 Nov 2015, 12:56

Re: IE COM get active tab

21 Apr 2017, 08:45

Xeo786 wrote:
euras wrote:
how it should help me? there is tips for catching an active IE or creating a New one if there is no old one. In my scenario there is allready 2 tabs in IE With the same Title and I searching ways to show the code witch tab the code should take in that scenario (the active one).
WB := IEGET() gona work for active window .... at least working for me just give it a try ... ;)
so you are saying I should use

Code: Select all

pwb := IEGET()
instead of

Code: Select all

pwb := IEGet("Service")
?
User avatar
Xeo786
Posts: 238
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: IE COM get active tab

21 Apr 2017, 08:55

euras wrote:
so you are saying I should use

Code: Select all

pwb := IEGET()
instead of

Code: Select all

pwb := IEGet("Service")
?
haven't you seen the example by blackholyman

Code: Select all

IE := IEGet()   ; this will going to put handles to active window
if !IE              ; if no internetexplorer is running then  
{
    IE := ComObjCreate("InternetExplorer.Application") ; create application if needed
}
IEGet(name="") {
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame     ;// Get active window if no parameter
   Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - ((Windows|Microsoft) Internet Explorer|Internet Explorer)")
   for wb in ComObjCreate("Shell.Application").Windows
      if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
         return wb
}
this will work even if you have two IE windows having more then one tab, only active internet window with active tab going to be accessed ... :D
"When there is no gravity, there is absolute vacuum" -Game changer theory
euras
Posts: 404
Joined: 05 Nov 2015, 12:56

Re: IE COM get active tab

24 Apr 2017, 08:28

Xeo786 wrote:
euras wrote: this will work even if you have two IE windows having more then one tab, only active internet window with active tab going to be accessed ... :D
well, it doesn't work at all. I have 2 (or more) TABS in the same window With the same name and the code bellow takes the first tab With that name instead of active one.

Code: Select all

pwb.Visible := True

IE := IEGet()   ; this will going to put handles to active window
if !IE              ; if no internetexplorer is running then  
{
    IE := ComObjCreate("InternetExplorer.Application") ; create application if needed
}

pwb := IEGet("Service")
Loop{
    sleep 100
	one := pwb.document.getElementById("contentIFrame0").contentDocument.getElementById("IFRAME_EditTask").contentDocument.getElementsByTagName("DIV")[48].innerText
    if (one <> "some text"){
        pwb := IEGet("Service")
        one := pwb.document.getElementById("contentIFrame0").contentDocument.getElementById("IFRAME_EditTask").contentDocument.getElementsByTagName("DIV")[48].innerText
        sleep 100
    }
}until (one = "some text")
msgbox %one%
Return

IEGet(Name="")        ;Retrieve pointer to existing IE window/tab
{
    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
        Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
        : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
    For pwb in ComObjCreate( "Shell.Application" ).Windows
        If ( pwb.LocationName = Name ) && InStr( pwb.FullName, "iexplore.exe" )
            Return pwb
} ;written by Jethrow
User avatar
Xeo786
Posts: 238
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: IE COM get active tab

24 Apr 2017, 08:52

:shock: just use pwb where ever you want to handle active tab according to your code,

Code: Select all

pwb := IEGet()
not the

Code: Select all

pwb := IEGet("Services")
"When there is no gravity, there is absolute vacuum" -Game changer theory
euras
Posts: 404
Joined: 05 Nov 2015, 12:56

Re: IE COM get active tab

24 Apr 2017, 09:14

Xeo786 wrote::shock: just use pwb where ever you want to handle active tab according to your code,
Nope, it doesn't help :/ If I set pwb := IEGet() in a loop, the loop doesn't run at all. If I set TAB name there - everything Works fine except that the code takes the first one tab instead of the active one :/

Code: Select all

pwb.Visible := True
pwb := IEGet()
Loop{
    sleep 100
	one := pwb.document.getElementById("contentIFrame0").contentDocument.getElementById("IFRAME_EditTask").contentDocument.getElementsByTagName("DIV")[48].innerText
    if (one <> "some text"){
        pwb := IEGet()
        one := pwb.document.getElementById("contentIFrame0").contentDocument.getElementById("IFRAME_EditTask").contentDocument.getElementsByTagName("DIV")[48].innerText
        sleep 100
    }
}until (one = "some text")
msgbox %one%
Return
DanielToward13
Posts: 71
Joined: 18 May 2017, 10:56

Re: IE COM get active tab

07 Dec 2017, 19:13

try the below code from https://autohotkey.com/boards/viewtopic ... 94#p168894 by jeeswg

Code: Select all

q:: ;get active tab from a specific window
WinGet, hWnd, ID, A
;WinGet, hWnd, ID, ahk_class IEFrame
oWB := WBGet("ahk_id " hWnd)
MsgBox, % oWB.document.title "`r`n" oWB.document.url
oWB := ""
return

;==================================================

w:: ;loop through all tabs (and get tab by hWnd/title/url)
vOutput := ""
;hWnd := "MyHWnd"
hWnd := 0
for oWB in ComObjCreate("Shell.Application").Windows
	if (!hWnd || (hWnd = oWB.HWND))
	&& (oWB.Name = "Internet Explorer")
	{
		vOutput .= oWB.document.title "`r`n" oWB.document.url "`r`n`r`n"
		;if (oWB.document.title = "MyTitle")
		;	break
		;if (oWB.document.url = "MyUrl")
		;	break
	}
MsgBox, % oWB.document.title "`r`n" oWB.document.url
oWB := ""
Clipboard := vOutput
MsgBox, % vOutput
return

;==================================================

WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ; based on ComObjQuery docs
   static   msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
   ,   IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp
;   ,   IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], boiler, Dario91, mikeyww, PlumpSamurai, sebbulon and 55 guests