新标签中的Chrome,Javascript,window.open [英] Chrome, Javascript, window.open in new tab

查看:503
本文介绍了新标签中的Chrome,Javascript,window.open的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Chrome中,这会在新标签页中打开:

In chrome this opens in a new tab:

<button onclick="window.open('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">
  window.open('newpage.html', '_blank');
</script>

这可行吗?

推荐答案

您无法直接控制它,因为它是由Internet Explorer用户控制的选项。

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

使用具有不同窗口名称的Window.open打开页面将在新的浏览器窗口中打开,如弹出窗口,或在新选项卡中打开,如果用户将浏览器配置为这样做。

Opening pages using Window.open 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.

编辑:

更详细的解释:

1. 在现代浏览器中,window.open将在新标签页中打开,而不是弹出窗口。

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

2. 您可以通过在第3个参数中指定选项来强制浏览器使用新窗口('弹出窗口')

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

3. 如果window.open调用不属于用户启动的事件,则会在新窗口中打开。

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

4. 用户启动的事件不必进行相同的函数调用 - 但它必须来自用户调用的函数单击

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. 如果用户启动事件委托或推迟函数调用(在未绑定到click事件的事件侦听器或委托中,或者例如使用setTimeout),则会丢失它的状态为用户启动

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。某些弹出窗口阻止程序将允许从用户启动的事件打开的窗口,但不会打开那些打开的窗口。

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

7. 如果任何弹出窗口被阻止,阻止者通常允许的那些(通过用户启动的事件)有时也会被阻止。
一些例子......

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:

window.open('page.php', '', 'width=1000');

以下内容有资格作为用户发起的事件,即使它调用另一个函数:

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

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

以下不符合用户启动的事件,因为setTimeout推迟了它:

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

function g(){
  setTimeout(o, 1);
}
function o(){
  window.open('page.php');
}
$('button').addEvent('click', g);

这篇关于新标签中的Chrome,Javascript,window.open的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆