80

I use target="_blank" to open links in a new tab. But in IE it opens a new window which is completely logical because that is what _blank is supposed to do.

And i don't know how target="_blank" behaves in other browsers.

Is there something to force links to open in a new tab. If the browser supports tabs... else make a new window

2
  • 6
    target="_blank" will open the link in a new tab in Firefox, Chrome and Opera. The other two browsers, IE and Safari will open it in a new window. Oct 19, 2010 at 17:04
  • 1
    Wow, you can't even use a named target and have IE open new links in your named tab. That is, if you choose to open a link in a new tab with target="myName", subsequent links with the same target will not open in your tab but will open a new window. Sounds like a usability bug to me. Thanks IE.
    – Matthew
    May 27, 2012 at 16:23

14 Answers 14

81

There is no way to do that as the author of the HTML that a browser renders. At least not yet that I know of. Its pretty much up to the browser and its settings / preferences that are set by users themselves.

Also, you shouldn't impose this upon any user. A browser is the user's property. If a user wants to open all links in tabs or in new windows, then let the user do exactly that.

It's good that we can't do certain things. target=_blank is still abused and popups have been done to death.

8
  • 19
    +1! By default most browsers open target = "_blank" in new tab, but in the old days, it would open a new window. There, I think, is no way to force links to open in new tab. Oct 19, 2010 at 17:05
  • 6
    A option to define which links should open in a new tab/window should exist. This is convenient for external links. I believe that everybody agrees that opening the link in a new tab is the desired method for most users. IE and Safari open _blank's in new windows for some reason, but that is probably a legacy behavior and has nothing to do with the user's preferences. I believe that most users even don't know how to set this behavior in their browsers. Oct 19, 2010 at 17:18
  • 4
    The simple solution is not to try to force your links to open in a new tab or a new window. If I want a new tab, I'll middle-click, thanks.
    – bobince
    Oct 19, 2010 at 18:04
  • 4
    The visitor decides when they are going to leave your site, not you, so it doesn't matter if you don't want them to leave. If the visitor doesn't want to leave then they can middle click (as @bobince already indicated). If they leave and want to come back then they have a back button … and a browser history … and a bookmarks menu … and probably the ability to simply find the site again.
    – Quentin
    Oct 19, 2010 at 18:36
  • 17
    You are also forgetting that in some websites, opening the link in the same tab can be just inconvenient. Suppose you're viewing an email message, and you clicked a link, it would be really an overkill having to reload the message again. Gmail does force opening non-local links in new tabs.
    – Chris
    Jan 3, 2012 at 11:46
43

Since I fell into this old question and then found that it is now possible (maybe this css option wasn't available then), I just want to add an update on how it can be done:

<a href="[yourlink]" target="_blank" style="target-new: tab;">Google</a>

Here are the options for the target-new style:

target-new: window | tab | none 

Didn't test the none option, maybe it uses the default browser setting.

I confirmed this for Firefox and IE7-9.

10
10

No, there isn't.

1
  • 7
    Blunt, to the point, definitive answer =) I really want to edit this answer to just "No"
    – earcam
    Jul 17, 2014 at 22:38
8

I hope this will help you

window.open(url,'_newtab');

1
  • 1
    window.open returns a windowObjectReference which can be reused (alternatively the 2nd arg window name can be reused in subsequent calls to load different urls in the same tab/window). However this does not answer the question - window.open provides no way of forcing tab or window.
    – earcam
    Jul 17, 2014 at 22:44
2

I didn't try this but I think it works in all browsers:

target="_parent"

1
  • 1
    new tab is highly dependent on user settings and browser agent. 'Open Link In A New Tab' should not be made a requirement anywhere in the design of side, learned that over the last year.
    – Moon
    Aug 5, 2013 at 4:14
1

The way the browser handles new windows vs new tab is set in the browser's options and can only be changed by the user.

2
  • 1
    user preference is one thing, but what i have learnt so far is that you need to have PHP setting different approaches for different browsers.
    – Moon
    Mar 19, 2012 at 19:07
  • 1
    Really? How have you done it with PHP?
    – Moin Zaman
    May 27, 2012 at 11:54
1
onclick="window.open(this.href,'_blank');return false;"
1
a {
    target-name: new;
    target-new: tab;
}

The target-new property specifies whether new destination links should open in a new window or in a new tab of an existing window.

Note: The target-new property only works if the target-name property creates a new tab or a new window.

2
  • 1
    It works for the newest Firefox.
    – user3242943
    Jan 21, 2015 at 11:15
  • It seems weird to handle this in CSS. I guess it's nice to be able to apply it via CSS selector, but it seems like this goes against the traditional separation of concerns. Apr 12, 2018 at 23:24
0

You can change the way Safari opens a new page in Safari > Preferences > Tabs > 'Open pages in tabs instead of windows' > 'Automatically'

0

You can set IE to open links in new tab, just go to the settings menu.

0

In Internet Explorer, click the Tools -> Internet Options. Click General tab -> Tabs -> Settings. Choose "When a pop-up is encountered"-> Always open pop up in new tab option. Click OK.

0
0

It is possible!

This appears to override browser settings. Hope it works for you.

<script type="text/javascript">
// Popup window code
function newPopup(url) {
    popupWindow = window.open(url,'popUpWindow1','height=600,width=600,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>

<body>
  <a href="JavaScript:newPopup('http://stimsonstopmotion.wordpress.com');">Try me</a>
</body>
0

Simply using "target=_blank" will respect the user/browser preference of whether to use a tab or a new window, which in most cases is "doing the right thing".

If you specify the dimensions of the new window, some browsers will use this as an indicator that a certain size is needed, in which case a new window will always be used. Stack overflow code example Stack Overflow

-1

Try with javascript function like this

Html:

<a href="javascript:void(0)" onclick="open_win()">Target</a>

Javascript:

<script>
function open_win() 
{
window.open("https://www.google.co.in/");
}
</script>
1
  • Thanks one really helps - to set href as javascript: ! Nov 7, 2015 at 0:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.