Yes, either change the browser preferences or use whatever key and click combination is required for that browser to open the link in a new tab but keep focus on the current on. You can't do it with script. Leave it up to the user.
How to check if an opened browser window is closed or not in JavaScript? To check if an opened browser window is closed, you can use the closed property in referenced window object in JavaScript. The property returns a boolean true if the window is closed and false if the window is in the opened state.
The location property of a window (i.e. window. location ) is a reference to a Location object; it represents the current URL of the document being displayed in that window. Since window object is at the top of the scope chain, so properties of the window. location object can be accessed without window.
window.open('https://support.wwf.org.uk', '_blank');
The second parameter is what makes it open in a new window. Don't forget to read Jakob Nielsen's informative article :)
I don't think there's a way to do this, unless you're writing a browser extension. You could try using window.open
and hoping that the user has their browser set to open new windows in new tabs.
You can even use
window.open('https://support.wwf.org.uk', "_blank") || window.location.replace('https://support.wwf.org.uk');
This will open it on the same tab if the pop-up is blocked.
This works for me on Chrome 53. Haven't tested anywhere else:
function navigate(href, newTab) {
var a = document.createElement('a');
a.href = href;
if (newTab) {
a.setAttribute('target', '_blank');
}
a.click();
}
with jQuery its even easier and works on Chrome as well
$('#your-button').on('click', function(){
$('<a href="https://www.some-page.com" target="blank"></a>')[0].click();
})
Rather going for pop up,I personally liked this solution, mentioned on this Question thread JavaScript: location.href to open in new window/tab?
$(document).on('click','span.external-link',function(){
var t = $(this),
URL = t.attr('data-href');
$('<a href="'+ URL +'" target="_blank">External Link</a>')[0].click();
});
Working example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With