82

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

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189
Moon
  • 19,518
  • 56
  • 138
  • 200
  • 7
    `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. – Šime Vidas Oct 19 '10 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 '12 at 16:23

14 Answers14

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.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
Moin Zaman
  • 25,281
  • 6
  • 70
  • 74
  • 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. – tomsseisums Oct 19 '10 at 17:05
  • 7
    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. – Šime Vidas Oct 19 '10 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 '10 at 18:04
  • 1
    @bobince What about external links? If I (as the owner of the web-site) want to provide a link to an external page (as in an article), but I don't want the visitor to navigate away (nor does the visitor (!!)), then there should be a method do accomplish this. – Šime Vidas Oct 19 '10 at 18:31
  • 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 '10 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 03 '12 at 11:46
  • 1
    Yes, I agree that there is some logic to opening new windows / tabs for web-apps like gmail. – Moin Zaman Feb 15 '12 at 04:09
  • 1
    It IS possible to force links opening in a new window, posted by "DNS" in this similar question: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab, just make sure you will in the 'specs' parameter for a window.open – patrick Dec 13 '12 at 10:30
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.

Martin
  • 3,018
  • 1
  • 26
  • 45
  • 1
    I have Safari 5.1.7. (think it is latest for Windows), and this is not working for me. Maybe it is for Safari 6+? Can anyone confirm this? – Mladen Janjetovic Sep 20 '13 at 14:56
  • 3
    Well, it's not very well documented, I checked in caniuse.com but no info, the definition is here: http://www.w3.org/TR/css3-hyperlinks/#the-target-new. w3schools states it is not supported by any browser (http://www.w3schools.com/cssref/css3_pr_target-new.asp), but it does work on Firefox and IE at least, so it's a hard one to find info... – Martin Sep 23 '13 at 08:22
  • 1
    http://www.w3schools.com/cssref/css3_pr_target-new.asp – Bill Bunting Oct 25 '13 at 20:14
  • 1
    @BillBunting, it's finally the same Reference I had posted. However, they say no browser supports it, but I have tested it and it is working... It's strange that such an old definition is not clearly documented... – Martin Oct 28 '13 at 12:46
  • 2
    It's insane that this definition would even be necessary. Why wouldn't they simply define another value for the target attribute? – Dom Ramirez Aug 11 '14 at 02:49
  • 1
    Well, maybe because how it works, you can create a new tab with a name (`target="someTab" style="target-new: tab;"`) and then address to that tab with the target on some other place to get to the tab. In this way it makes sense, but it's still strange that it is nowhere documented properly... – Martin Aug 11 '14 at 14:13
  • 2
    not working for me too – neel shah Oct 27 '14 at 10:42
  • @neelshah et al - CSS3 did propose `target-new:`, but between 2013 (when Martin posted this answer) and 2016, the [specification has been abandoned](http://stackoverflow.com/a/4907854/951830) – Robotnik Feb 17 '16 at 06:11
  • By today, this is not yet supported in any of the major browsers. – Sergiu Apr 15 '16 at 10:23
  • I am using Chrome on Windows 7 and I can confirm that this works. – santos Nov 16 '16 at 10:15
11

No, there isn't.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
8

I hope this will help you

window.open(url,'_newtab');

Nasruddin
  • 1,640
  • 14
  • 20
  • 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 '14 at 22:44
2

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

target="_parent"

Robert
  • 5,278
  • 43
  • 65
  • 115
Tiago
  • 29
  • 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 05 '13 at 04:14
1
onclick="window.open(this.href,'_blank');return false;"
ericmotil
  • 19
  • 2
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.

  • 1
    It works for the newest Firefox. –  Jan 21 '15 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. – Paul-Hebert Apr 12 '18 at 23:24
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.

Andrew W.
  • 27
  • 1
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.

Santhosh
  • 89
  • 1
  • 3
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

0

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

dev_doctor
  • 722
  • 6
  • 10
0

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

Lucas Matos
  • 1,112
  • 5
  • 25
  • 42
-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>
Jkar
  • 9