Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

IEGet via URL instead of Name



  • Please log in to reply
5 replies to this topic
levisimcoe
  • Members
  • 18 posts
  • Last active: Aug 04 2016 10:17 PM
  • Joined: 03 Nov 2013

Hey guys, curious if anyone knows of a way to retrieve an existing IE window/tab based on URL instead of name?  I have two tabs that have the same name and PID's but different URL's.  I have included Jethrow's script below for recalling windows/tabs based on the tab name.  In the script I'm working on, I have stored the name of the URL in a variable, that I would like to be able to use in order to retrieve the correct IE window.  

 

When using the last line (wb := IEGet ("") I have found that it will bring back the last active window.  The issue I have with this is when attempting to send something to a control on the last active window, it doesn't send correctly because both tabs have the same name and PID.

 

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 wb in ComObjCreate( "Shell.Application" ).Windows
        If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
            Return wb
} ;written by Jethrow
wb := IEGet("")

 



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Tyrer helped me out in another post regarding how to interact with multiple tabs (albeit I have ye to test the code and make sure I understand it):

 

 


link:= "http://www.google.co.uk"
wb := comobjcreate("internetexplorer.application")
wb.navigate(link)
wb.visible:=true
While wb.readyState !=4 || wb.document.readyState !="complete" || wb.busy
Sleep 100

newlink := "http://www.bbc.co.uk"
wb.Navigate( newlink , 2048)

sleep, 200
    For wbs in ComObjCreate("Shell.Application").Windows
    If InStr(wbs.locationURL, "bbc.co.uk")
    newwb:=wbs
sleep, 200

msgbox % newwb.LocationName

 

Based on this, it would see you can use wb.LocationURL instead of wb.LocationName to get a match.



Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
✓  Best Answer
;)
IEGetbyURL(URL) {	; http://www.autohotkey.com/board/topic/102723-ieget-via-url-instead-of-name/#entry636586
    For pwb in ComObjCreate("Shell.Application").Windows
        If (pwb.LocationURL = URL and InStr(pwb.FullName, "iexplore.exe") > 0)
        Return pwb
}

My Website • Recommended: AutoHotkey Unicode 32-bit • Join DropBox, Copy


levisimcoe
  • Members
  • 18 posts
  • Last active: Aug 04 2016 10:17 PM
  • Joined: 03 Nov 2013

Thanks for that.  I have this so far:

 

WinGetActiveTitle, winTitle
ControlGet, siteAddress, Line, 1, Edit1, %winTitle%
 
As you can see, I store the URL of the active window under the variable %siteAddress%.  The URL that is recorded under the variable is:
 
I then switch through different windows (which all works fine) and then I get to your suggestion:
 
IEGetbyURL(URL) { ; 
    For pwb in ComObjCreate("Shell.Application").Windows
        If (pwb.LocationURL = URL and InStr(pwb.FullName, "iexplore.exe") > 0)
        Return pwb
}
 
I then added this:
 
wb := IEGetbyURL("%siteAddress%")
I was trying to recall the window via the variable that was stored earlier.
 
When I try recalling the variable that was stored earlier I get an error that says:
Error:  The following variable name contains an illegal character:
 
The weird thing is I can paste the same URL where %siteAddress% is in the line above, and the script will work perfectly.  I don't get it, am I missing something?  I don't think I'm using the variable incorrectly as it's inputting the correct URL but for some reason it is saying there is an illegal character...


tyrer
  • Members
  • 270 posts
  • Last active: Apr 10 2015 05:10 PM
  • Joined: 23 Sep 2012
wb := IEGetbyURL(siteaddress)


levisimcoe
  • Members
  • 18 posts
  • Last active: Aug 04 2016 10:17 PM
  • Joined: 03 Nov 2013

Works like a charm.  Thanks for all your help.