How to stay on the current window when the link opens in a new tab?
No, there a no way to stay on the current window instead of going to the tab because it is controlled by the browser.
Some basic about Window open method:-
window.open(url, "_self");
- _blank – URL is loaded into a new window. This is the default.
- _parent – URL is loaded into the parent frame.
- _self – URL replaces the current page.
- _top – URL replaces any framesets that may be loaded name – The name of the window.
Try JavaScript to open a new tab but stay on the current page
You can do a popup new tab over the current page with less height and width.
<html>
<body>
<script>
myWindow=window.open('https://eyehunts.com/','','width=400,height=250')
//myWindow.document.write("<p>This is 'myWindow'</p>")
myWindow.focus()
</script>
</body>
</html>
Output:
Open tabs in the background using JavaScript is not possible because this is set in the user’s preferences in about:config
, which you have no control over. The setting is:
browser.tabs.loadDivertedInBackground=true
Do comment about this topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version
I am not following.
How exactly your code is showing how to stay on the current tab?
It’s no, clickbait title.