window.open行为在铬制表符/窗口 [英] window.open behaviour in chrome tabs/windows

查看:91
本文介绍了window.open行为在铬制表符/窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一小部分javascript打算打开两个或更多标签。这在FF和IE中可以正常工作,但是chrome会在新窗口而不是选项卡中打开第二个窗口。它不依赖于url,因为我已经用两个相同的url进行了尝试。第一次在新窗口中打开,第二次在新窗口中打开。

I have a small bit of javascript intended to open two or more tabs. This works fine in FF and IE, but chrome opens the second one in a new window instead of tab. It isn't dependant on the url as I've tried it with two identical url's. First opens in tab, second one in new window.

以下是我的代码段:

Here's my code snippet:

for(var i=0 ; i<sites.length ;i++)
{
    window.open(sites[i].Url);
}


推荐答案

Chrome会自动打开一个网址只有在用户生成操作时才有新选项卡,每个用户操作限制为一个选项卡。在任何其他情况下,URL将在新窗口中打开(在BT中,默认情况下Chrome会阻止该URL)。必须在回调中调用

window.open 这是由用户操作(例如onclick)触发的,用于在新选项卡而不是窗口中打开页面。

Chrome automatically opens a URL in a new tab only if it's user generated action, limited to one tab per user action. In any other case, the URL will be opened in a new window (which, BTW, is blocked by default on Chrome).
window.open must be called within a callback which is triggered by a user action (e.g. onclick) for the page to open in a new tab instead of a window.

在您的示例中,您尝试打开N个选项卡在用户操作之后。但只有第一个在新选项卡中打开(因为它是用户生成的操作)。之后,任何其他URL将在新窗口中打开。

In your example, you attempt to open N tabs upon user action. But only the first one is opened in a new tab (because it's a user generated action). Following that, any other URL will be opened in a new window.

类似的问题:(请参阅maclema的答案)

Similar question: force window.open() to create new tab in chrome (see answer by maclema)

这篇关于window.open行为在铬制表符/窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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