Jump to content

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

[Solved]Creating a new IE Tab instead of new window if it exists


  • Please log in to reply
8 replies to this topic
GodlyCheese
  • Members
  • 719 posts
  • Last active: Nov 11 2014 07:12 PM
  • Joined: 30 Aug 2012
I have very limited COM skills, they're improving but this is still beyond me. I'm currently using:

pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := True
pwb.Navigate(OutputVar4)
While, (pwb.ReadyState != 4)
   Sleep, 100

To run URLs that require IE since my default browser is Firefox. I didn't write this, I've seen it used in a few places and copied it. Does anyone have any tips for having COM create a new tab in my existing IE window instead of creating a new window, assuming an IE window exists? I've figured out how to pull this off if I make my pre-existing IE window with COM but if I open IE by clicking instead of COM then I can't figure out how to create a new tab in that. My script will just open a new window instead.

I can't write in COM well. I've seen several threads dealing with creating new IE tabs in pre-existing non-COM created IE windows (like http://www.autohotke...age__hl__ie tab) but can't figure out how to repurpose them for myself since they have all sorts of other things in them and idk what does what for the life of me.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
You can easily loop trough all your Explorer windows like this:
for wb in ComObjCreate("Shell.Application").Windows

   MsgBox % wb.locationName "`n" wb.locationURL



GodlyCheese
  • Members
  • 719 posts
  • Last active: Nov 11 2014 07:12 PM
  • Joined: 30 Aug 2012
Tyvm however I don't want to loop through all my explorer windows, because the loop isn't limited to Internet Explorer. Your script also loops through all of my Windows Explorer windows. I've tried to remedy this issue, but can't even test properly because I'm missing the IEGet function. I can't find a working link to download the function either. Here's my attempt at writing what I need, which probably doesn't work (like I said I can't really test without IEGet):

OutputVar4 = www.google.com

For wb in ComObjCreate("Shell.Application").Windows
   {
   If (wb.LocationURL <> "")
      {
      SearchString := wb.LocationURL
      IfNotInString, SearchString, File:///
         {
         pwb := IEGet(wb.LocationName)
         Break
         }
      }
   }
If pwb =
   pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := True
pwb.Navigate(OutputVar4)
While, (pwb.ReadyState != 4)
   Sleep, 100
Return

Any advice?

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008
OutputVar4 = www.google.com



if	 hWnd :=	 WinExist("ahk_class IEFrame")

{

   For wb in ComObjCreate("Shell.Application").Windows

   {} Until	 (hWnd = wb.hwnd)

}

else

{

   wb := ComObjCreate("InternetExplorer.Application")

   While   (wb.ReadyState != 4)

	  Sleep, 50

   wb.Visible := True

}

wb.Navigate(OutputVar4)

While, (wb.ReadyState != 4)

   Sleep, 100

Return


GodlyCheese
  • Members
  • 719 posts
  • Last active: Nov 11 2014 07:12 PM
  • Joined: 30 Aug 2012
That looks like it should work, but it doesn't and I can't figure out why. Instead of creating a new tab if IE exists your script simply uses my first tab and navigates to OutputVar4. If IE isn't running your script does nothing.

On a scale of 1 to "confused" I am now a snuffleupagus.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

Any advice?

Try, Fail, Adjust ... Repeat. Once your frustration gets to the point that you almost pass out due to exhaustion, in desperation your mind will start to think about things differently. True genius can be found at this point ....

... or just try this:
OutputVar4 = www.google.com

if  hWnd :=  WinExist("ahk_class IEFrame")
{
   For wb in ComObjCreate("Shell.Application").Windows
   {} Until  (hWnd = wb.hwnd)
   params := [OutputVar4, 2048]
}
else
{
   wb := ComObjCreate("InternetExplorer.Application")
   wb.Visible := True
   params := [OutputVar4]
}
wb.Navigate(params*)
While, (wb.ReadyState != 4)
   Sleep, 100
Return

Your script also loops through all of my Windows Explorer windows. I've tried to remedy this issue ...

for wb in ComObjCreate("Shell.Application").Windows
   MsgBox % wb.locationName "`n" wb.locationURL "`n" wb.FullName


Alpha Bravo
  • Members
  • 1687 posts
  • Last active: Nov 07 2015 03:06 PM
  • Joined: 01 Sep 2011
OutputVar4 = www.google.com

if pwb := IEGet() ; if existing IE

    Pwb.Navigate2(OutputVar4, navOpenInNewTab := 2048) ; Navigate in a new Tab

else

{

    Pwb := ComObjCreate("InternetExplorer.Application")

    Pwb.Visible := True

    Pwb.Navigate(OutputVar4)

}

WinActivate, Internet Explorer

return



IEGet(Name="")

{

   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


GodlyCheese
  • Members
  • 719 posts
  • Last active: Nov 11 2014 07:12 PM
  • Joined: 30 Aug 2012
I should really invest the time to thoroughly go through your COM threads Jethrow. I can honestly say that if by some miracle I came up with that solution it wouldn't have been a stroke of genius, it would have been blind luck because I lack a fundamental understanding of the whole ternary/com/whatever this concept is.

Starting to get a better grasp on it now though. Tyvm.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
.