Some websites open links in a new tab, and I find this incredibly annoying. Is there any way to force links to open in the same tab, instead of opening a new one?
How to open a link in same tab in browser extension popup?
Is there a way to force any links to open in the same window of the browser?
Open links in same tab in Chrome - Google Chrome Community
Chrome Extension: How do i open urls in popup.html in the same tab - Stack Overflow
Videos
There is an extension called OpenHere that will do this. It will add the option in the right click context menu Open in This Window. Just right clcik on the link you want to open in the same tab.
Edit in response to comment:
You can do it with AutoHotkey. You have need to download it and install it on your PC. After that just copy the code below and save it with a .ahk extension.
SetTitleMatchMode, RegEx
#IfWinActive, - Google Chrome$
!RButton::
!LButton::
KeyWait, Alt
Click, Right
SendInput, e
ControlFocus, Chrome_OmniboxView1
SendInput, ^a{Backspace}
SendInput, ^v{Enter}
return
#IfWinActive
Now when you press Alt + LClick, it will copy the link to the clipboard and past it in the address bar of Chrome. Just press the button and click and release with the click and the link will open in the same tab.
If autohotkey is is the way you want to go, there's a much simpler way of doing it:
#IfWinActive ahk_exe chrome.exe
!LButton::
Send, ^{LButton}
Send, ^{F4}
return
#IfWinActive
This just ctrl-clicks wherever the mouse is and then closes the current tab when you alt-click anywhere on a chrome tab. And since it isnt sophisticated enough to activate ONLY when clicking on a link, you could also use it as a shortcut to close the current tab by alt-clicking anywhere on the tab.
Looking for a solution to force any links to open in the same window of the chrome browser instead of opening in a new window.
Holding Ctrl+Left click doesn't work for all kinds of links.
"Open link in the same tab, pop-up as tab" extension doesn't work on some links.
I believe that chrome does not allow the popups to open an external page by any way. The only solution I know is to place an iframe in your popup.html file with src attribute set to popup2.html and place all your html inside popup2.html. However, consider that all websites do not work well inside iframe.
If you are trying to open url in currently active tab then try following:
Attach following script to your popup.html file:
var hrefs = document.getElementsByTagName("a");
function openLink() {
var href = this.href;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tab = tabs[0];
chrome.tabs.update(tab.id, {url: href});
});
}
for (var i=0,a; a=hrefs[i]; ++i) {
hrefs[i].addEventListener('click', openLink);
}
You need to add tabs permisson to your manifest file for this to work.
You only need to use chrome.tabs.update({active: true, url: 'yoursite.com'}); instead of chrome.windows.create({url:'yoursite.com'}); and the location will be opened in the same active tab
Installing the "Open PinnedTab Link" Chrome extension with the settings below and restarting the browser helped to solve this problem. Links clicked within the same domain inside a pinned tab open in the same tab whereas external links open in a new tab.
- Enabled: Clicked links will open in new tabs. - OFF
- Outbound Links Only: Keep links to the same domain in the pinned tab. - ON
If anybody's still interested, I made an extension that accomplishes this‒ "New Domain in New Tab" supports whitelists/blacklists on a per-domain basis, so you can fine-tune which sites it is enabled/disabled for.
Find it on the Chrome store: https://chrome.google.com/webstore/detail/new-domain-in-new-tab/nokdeeoiaiicgnonknihiccadnnmpeoh