I'm trying to open a URL in a new tab, as opposed to a popup window.
I've seen related questions where the responses would look something like:
window.open(url,'_blank'); window.open(url);
But none of them worked for me, the browser still tried to open a popup window.
To open a link in a new browser window, hold the Shift on then click the link or right-click the link and select Open link in New Window.
Configuring links to open in a separate tab is accomplished by adding text to the end of your page URL. This instructs the web browser to open the link in a new tab.
Open Link in New Tab Generally, you can hold down the control button – or the command key on a Mac computer – to open a link in a new tab. You can also click on a link and hold down the mouse without releasing, dragging the link to the browser's tab bar to open it in a new tab.
Internal vs. External Links. Links that take users to another page on the same website are internal links. Internal links should never open in new browser tabs, but rather the same tab the user is on.
This is a trick,
function openInNewTab(url) { window.open(url, '_blank').focus(); } //or just window.open(url, '_blank').focus();
In most cases, this should happen directly in the onclick
handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM
object.
<div onclick="openInNewTab('www.test.com');">Something To Click On</div>
http://www.tutsplanet.com/open-url-new-tab-using-javascript/
Nothing an author can do can choose to open in a new tab instead of a new window; it is a user preference. (Note that the default user preference in most browsers is for new tabs, so a trivial test on a browser where that preference hasn't been changed will not demonstrate this.)
CSS3 proposed target-new, but the specification was abandoned.
The reverse is not true; by specifying certain window features for the window in the third argument of window.open()
, you can trigger a new window when the preference is for tabs.
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