Andrew Andrew - 2 years ago 257
Javascript Question

Chrome, Javascript, in new tab

Hi everyone,

In chrome..

this opens in a new tab:

<button onclick="'newpage.html', '_blank')" />

this opens in a new window (but I'd like this to open in a new tab as well):

<script language="javascript">'newpage.html', '_blank');

Is this feasible?

Thank you,

Answer Source

You can't directly control this, because it's an option controlled by Internet Explorer users.

Opening pages using with a different window name will open in a new browser window like a popup, OR open in a new tab, if the user configured the browser to do so.


A more detailed explanation:

1. In modern browsers, will open in a new tab rather than a popup.

2. You can force a browser to use a new window (‘popup’) by specifying options in the 3rd parameter

3. If the call was not part of a user-initiated event, it’ll open in a new window.

4. A “user initiated event” does not have to the same function call – but it must originate in the function invoked by a user click

5. If a user initiated event delegates or defers a function call (in an event listener or delegate not bound to the click event, or by using setTimeout for example), it loses it’s status as “user initiated”

6. Some popup blockers will allow windows opened from user initiated events, but not those opened otherwise.

7. If any popup is blocked, those normally allowed by a blocker (via user initiated events) will sometimes also be blocked. Some examples…

Forcing a window to open in a new browser instance, instead of a new tab:'page.php', '', 'width=1000');

The following would qualify as a user-initiated event, even though it calls another function:

function o(){'page.php');
$('button').addEvent('click', o);

The following would not qualify as a user-initiated event, since the setTimeout defers it:

function g(){
  setTimeout(o, 1);
function o(){'page.php');
$('button').addEvent('click', g);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download