Always Opening a Link in a New Browser Tab Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Always Opening a Link in a New Browser Tab

Post by Alexander2 » 15 May 2022, 12:48

When I use the Run command to open an URL link in the Opera browser, the link is usually opened in a new tab. But AutoHotkey also often causes Opera to open a link in a new window rather than a new tab. Does anyone know how to prevent this from happening?

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab

Post by mikeyww » 15 May 2022, 14:00

You can post your script below. If you use Run with just the URL alone, it would open in a new tab.

Code: Select all

Run, http://www.autohotkey.com/
If your Windows registry has been altered from the default to handle URLs differently, you might get a different result.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 16 May 2022, 10:39

mikeyww wrote:
15 May 2022, 14:00
You can post your script below. If you use Run with just the URL alone, it would open in a new tab.

Code: Select all

Run, http://www.autohotkey.com/
If your Windows registry has been altered from the default to handle URLs differently, you might get a different result.
When I execute the command Run, http://www.autohotkey.com, the Opera browser opens the link in a new tab. However, links are not always opened in new tabs. For example, when I open https://mail.google.com/mail/u/0/#inbox , it is sometimes opened in a new window without any obvious reasons, but at other times, in a new tab. Does this have to do with system permissions which AutoHotkey has in regard to how it interacts with programs?

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab

Post by mikeyww » 16 May 2022, 10:49

OK. I'm not sure why. I triggered:

Code: Select all

F3::Run, https://mail.google.com/mail/u/0/#inbox
three times, and it opened in a new tab each time.

If your current browser window is somehow not accessible to AutoHotkey, I suppose that it could open a new instance. Others here may have more information for you.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 17 May 2022, 10:42

mikeyww wrote:
16 May 2022, 10:49
OK. I'm not sure why. I triggered:

Code: Select all

F3::Run, https://mail.google.com/mail/u/0/#inbox
three times, and it opened in a new tab each time.

If your current browser window is somehow not accessible to AutoHotkey, I suppose that it could open a new instance. Others here may have more information for you.
Yes, it is not clear why on my computer, AutoHotkey often opens links in new windows, although for the most part, it opens links in the same window in new tabs. The same link can be opened in either of the two ways in different instances.

Perhaps the Opera browser (opera.exe) has to be specified as the program which receives the argument (the link). What command can be used to send the argument specifically to this browser?

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab

Post by mikeyww » 17 May 2022, 10:50

You can use Run, specify Opera as the target program, and then add the URL as a program parameter (after the program path)-- same as you would do on Windows command line.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 18 May 2022, 11:43

mikeyww wrote:
17 May 2022, 10:50
You can use Run, specify Opera as the target program, and then add the URL as a program parameter (after the program path)-- same as you would do on Windows command line.
Thank you. I will try adding the program .exe file name before URLs to see whether the links will always be opening normally.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 20 May 2022, 12:11

I have added opera.exe before URLs. (E.g. Run opera.exe https://mail.google.com/mail/u/0/#inbox.)
But on some occasions and for no obvious reasons, links are still opened in new windows. This does not follow a particular pattern, because sometimes this happens, but often does not. I do not know what the exact reason may be.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab

Post by mikeyww » 20 May 2022, 12:15

OK. I also do not know! Strange behavior. It seems to indicate that the original window is not identified or is tied up in a dialog, but I don't know what dialog that would be.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 21 May 2022, 11:07

I will add the command winactivate opera.exe before the Run [link] command to see whether a link will be opening in the same window if the window is activated first.

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab  Topic is solved

Post by mikeyww » 21 May 2022, 11:18

I doubt that it would help. One workaround is to paste the URL into the browser's address bar instead of using Run.

Code: Select all

browser = ahk_exe chrome.exe
url     = http://www.autohotkey.com/
#If WinExist(browser)
F2::
WinActivate
Send ^t
SoundBeep, 1500
SendInput {Text}%url%`n
Return
#If

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 22 May 2022, 10:27

mikeyww wrote:
21 May 2022, 11:18
I doubt that it would help. One workaround is to paste the URL into the browser's address bar instead of using Run.

Code: Select all

browser = ahk_exe chrome.exe
url     = http://www.autohotkey.com/
#If WinExist(browser)
F2::
WinActivate
Send ^t
SoundBeep, 1500
SendInput {Text}%url%`n
Return
#If
Thank you. This is a clever way to resolve the issue. I was not aware that the Ctrl + T shortcut can be used to open a new tab and then simply paste an address into the address field. The same shortcut works in the Opera browser.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 23 May 2022, 12:52

I have tried to run the following shorter test script for the Opera browser, but it does not work. Do you know what needs to be changed in it?

Code: Select all

space::
IfWinExist(ahk_exe opera.exe)
{
WinActivate ahk_exe opera.exe
Send ^{t}
SendInput {Text}http://www.autohotkey.com/`n
}
Return

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab

Post by mikeyww » 23 May 2022, 13:03

The AHK documentation is a great source of examples of each command and AHK function. You can give it a go when you run into issues like this.

Code: Select all

#IfWinExist ahk_exe opera.exe
Space::
WinActivate
Send ^t
SendInput {Text}http://www.autohotkey.com/`n
Return
#IfWinExist
IfWinExist is a deprecated command. WinExist is a function, which takes expressions.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 23 May 2022, 13:20

mikeyww wrote:
23 May 2022, 13:03

Code: Select all

#IfWinExist ahk_exe opera.exe
Space::
WinActivate
Send ^t
SendInput {Text}http://www.autohotkey.com/`n
Return
#IfWinExist
Thank you. What is the purpose of the parameters {Text} and `n in the command SendInput {Text}http://www.autohotkey.com/`n?

User avatar
mikeyww
Posts: 26596
Joined: 09 Sep 2014, 18:38

Re: Always Opening a Link in a New Browser Tab

Post by mikeyww » 23 May 2022, 13:26

If you remove `n, you will see the difference there, as `n is a line feed.

For text mode: https://www.autohotkey.com/docs/commands/Send.htm#SendText

You could get away without it for your specific URL here. If a URL contains a character that AHK would interpret as a special character, then text mode blocks that interpretation. You can try the URL in this post with and without text mode, to see how it works.

Alexander2
Posts: 348
Joined: 27 Apr 2019, 17:38

Re: Always Opening a Link in a New Browser Tab

Post by Alexander2 » 24 May 2022, 10:34

mikeyww wrote:
23 May 2022, 13:26
If you remove `n, you will see the difference there, as `n is a line feed.

For text mode: https://www.autohotkey.com/docs/commands/Send.htm#SendText

You could get away without it for your specific URL here. If a URL contains a character that AHK would interpret as a special character, then text mode blocks that interpretation. You can try the URL in this post with and without text mode, to see how it works.
Thank you for the explanations. I can see that the {Text} command is needed, because without it, the script for the browser does not work as intended.

Post Reply

Return to “Ask for Help (v1)”