JavaScript Open in a New Window, Not Tab

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

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.

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.

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.

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

how to open a new browser insatnce not tab with angualrjs

Try this http://plnkr.co/edit/f50fWHnLBC3Y43mx6iuO?p=preview

$window.open('/newwindow.html',"_blank", "toolbar=yes,scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");


Related Topics



Leave a reply



Submit