83

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
  • 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. Commented 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. Commented 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.

Sign up to request clarification or add additional context in comments.

8 Comments

+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.
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.
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.
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.
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.
|
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 Comments

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?
Well, it's not very well documented, I checked in caniuse.com but no info, the definition is here: w3.org/TR/css3-hyperlinks/#the-target-new. w3schools states it is not supported by any browser (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...
It's insane that this definition would even be necessary. Why wouldn't they simply define another value for the target attribute?
not working for me too
|
11

No, there isn't.

1 Comment

Blunt, to the point, definitive answer =) I really want to edit this answer to just "No"
8

I hope this will help you

window.open(url,'_newtab');

1 Comment

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.
2

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

target="_parent"

1 Comment

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.
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 Comments

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.
Really? How have you done it with PHP?
1
onclick="window.open(this.href,'_blank');return false;" 

Comments

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 Comments

It works for the newest Firefox.
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.
0

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

Comments

0

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

Comments

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.

Comments

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> 

Comments

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

Comments

-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 Comment

Thanks one really helps - to set href as javascript: !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.