new window doesn#39;t open as tab in Chrome(新窗口未在 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 中作为选项卡打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:新窗口未在 Chrome 中作为选项卡打开


- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07