新窗口未在 Chrome 中作为选项卡打开 [英] new window doesn't open as tab in Chrome

查看:25
本文介绍了新窗口未在 Chrome 中作为选项卡打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Chrome 构建的东西.

I'm building something ONLY for Chrome.

我想用 window.open 打开几个标签页(Chrome 会阻止它,但我可以启用它).但是 Chrome 将它们作为新窗口而不是标签打开!

I want to open several tabs with window.open (which Chrome blocks but I can live with enabling it). But Chrome opens them as new windows instead of tabs!

由于一些不清楚的原因,我只找到了关于 相反的信息.我怎样才能做到这一点?

And for some unclear reason I found only information regarding the opposite. How can I achive this?

如果是这样,我怎样才能在 Chrome 不阻止它们的情况下调用程序化标签打开?

And if at it, how can I invoke programmatic tab openings without Chrome blocking them?

我看过一些帖子说这是不可能的,那是浏览器的偏好.首先,我不知道如何设置该偏好!其次,我看到有人声称他们做到了,那么该相信谁呢?

I have seen some posts saying it's not possible and that's it's a browser preference. First of all, I have no idea how to set that preference! Secondly, I saw people claiming they did it, so who to believe to?

编辑 2:我发现 Chrome 会打开新窗口而不是打开标签,因为它是一个 JavaScript 窗口打开而不是用户点击.有谁知道我如何伪造真正的点击?因为调用点击事件仍然算作非用户点击

EDIT 2: I found out that Chrome opens new windows and not open tabs because it's a JavaScript window opening and not user clicks. Anyone knows how I can fake a real click? Because calling the click event still counts as not user clicks

推荐答案

如果您的弹出窗口是由直接用户操作创建的(未被弹出窗口阻止程序阻止)并使用默认选项,它将在新选项卡中打开.如果您以编程方式创建它,它将作为新窗口打开.没有办法改变这种行为.

If your popup is created by a direct user action (not blocked by the popup blocker) and using the default options it will open in a new tab. If you create it programmatically, it will open as a new window. There is no way to change this behavior.

可以做什么,虽然这是一个非常糟糕的黑客,是在用户操作上创建弹出窗口,然后稍后使用对弹出窗口的引用将位置设置为最终目的地,比如以下:

What you can do, although it is a really bad hack, is create the popup on a user action and then set the location to the final destination using a reference to the popup later on, like the following:

<a href="javascript:;" id="testAnchor" />

var popup1 = null;

document.getElementById('testAnchor').onclick = function() {
    popup1 = window.open('about:blank', 'popup1');
}

  setTimeout(function() {
       popup1.location = 'LOCATION_ON_THE_SAME_ORIGIN_AS_THE_OPENER';

  }, 5000);

这篇关于新窗口未在 Chrome 中作为选项卡打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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