Make a link open a new window (not tab)
With pure HTML you can't influence this - every modern browser (= the user) has complete control over this behavior because it has been misused a lot in the past...
HTML option
You can open a new window (HTML4) or a new browsing context (HTML5). Browsing context in modern browsers is mostly "new tab" instead of "new window". You have no influence on that, and you can't "force" modern browsers to open a new window.
In order to do this, use the anchor element's attribute target
[1]. The value you are looking for is _blank
[2].
<a href="www.example.com/example.html" target="_blank">link text</a>
JavaScript option
Forcing a new window is possible via javascript - see Ievgen's excellent answer below for a javascript solution.
(!) However, be aware, that opening windows via javascript (if not done in the onclick event from an anchor element) are subject to getting blocked by popup blockers!
[1] This attribute dates back to the times when browsers did not have tabs and using framesets was state of the art. In the meantime, the functionality of this attribute has slightly changed (see MDN Docu)
[2] There are some other values which do not make much sense anymore (because they were designed with framesets in mind) like _parent
, _self
or _top
.
JavaScript open in a new window, not tab
Specify window "features" to the open
call:
window.open(url, windowName, "height=200,width=200");
When you specify a width/height, it will open it in a new window instead of a tab.
See https://developer.mozilla.org/en-US/docs/Web/API/Window.open#Position_and_size_features for all the possible features.
Open link new window (not tab) with JavaScript without typing the URL twice?
<a href="print.html" onclick="window.open(this.href, 'newwindow', 'width=300, height=250'); return false;"> Print</a>
this.href
is a reference to the href
attribute of the element when in the onclick
handler.
Open link in new window , not in new tab
Try like
<li onclick="window.open('http://www.google.com','mywindow','height:400;width:400;')">Demo</li>
Javascript Method to Ensure Open in New Window (not Tab)
If you specify the width and height when you call window.open
, most browsers will open the link in a new window rather than a tab.
window.open(url, '_blank', 'width=300,height=200');
Fiddle: http://jsfiddle.net/kelervin/Pf8Rw/
See this question for discussion and more detail.
If the intent is to get the user's attention, you could consider adding desktop notifications (assuming a browser like Chrome that supports them is an option).
See this answer for an example, it might be just what you're looking for.
Open a URL in a new tab (and not a new window)
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.
HTML: how to force links to open in a new tab, not new window
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.
How to open an URL in a new tab not in a new window
This may help.
<div onclick="OpenNewTab('http://www.stackoverflow.com');">Click here to Open New Tab</div>
function OpenNewTab(url) {
var newwindow = window.open(url, '_blank');
newwindow .focus();
}
Working Fiddle
Target='_blank' to show in new window, NOT new tab, possible?
You cannot control this - it's entirely at the discretion of the user-agent; which is the point, after all. All you can specify is that the page be opened in a different viewpane context, and it's up to the user to decide how they want your window to take up their screen space/taskbar list/Alt-Tab shortcuts etc.
In fact I'd go even further and say that if at all possible you should avoid opening up a new tab/window at all. I know that I get a little annoyed when websites do this, and it feels a bit clunky and 1990s what with all the Ajax and floating divs and magic we have nowadays.
Related Topics
Add Border-Bottom to Table Row ≪Tr≫
When to Use the !Important Property in Css
Why Can't I Have a Numeric Value as the Id of an Element
Html Input="File" Accept Attribute File Type (Csv)
Play Local (Hard-Drive) Video File With Html5 Video Tag
Force Flex Item to Span Full Row Width
Percent Pie Chart With CSS Only
How to Apply Hovering on HTML Area Tag
Target="_Blank" Vs. Target="_New"
How to Submit Form on Change of Dropdown List
Is It Sometimes Bad to Use ≪Br /≫
How to Change Source of ≪Img≫ Tag on Hover
How to Make This Arrow in CSS Only
Inline-Block Boxes Not Fitting in Their Container