[英]new window doesn't open as tab in Chrome
I'm building something ONLY for Chrome. 我建立仅适用于Chrome的东西。
I want to open several tabs with window.open
(which Chrome blocks but I can live with enabling it). 我想用
window.open
打开几个标签(Chrome会阻止,但我可以使用它来启用它)。 But Chrome opens them as new windows instead of tabs! 但Chrome会将它们打开为新窗口而不是标签!
And for some unclear reason I found only information regarding the opposite. 由于一些不明原因,我发现只有相反的信息。 How can I achive this?
我怎么能得到这个?
And if at it, how can I invoke programmatic tab openings without Chrome blocking them? 如果在它,如何在没有Chrome阻止的情况下调用程序化选项卡?
EDIT: 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?
其次,我看到人们声称他们这样做了,所以谁相信?
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. 编辑2:我发现Chrome打开新窗口而不是打开标签,因为它是一个JavaScript窗口打开而不是用户点击。 Anyone knows how I can fake a real click?
任何人都知道如何伪造真正的点击? Because calling the click event still counts as not user clicks
因为调用click事件仍然算不是用户点击
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 Add on "One Window": https://chrome.google.com/webstore/detail/one-window/papnlnnbddhckngcblfljaelgceffobn Chrome在“一个窗口”上添加: https : //chrome.google.com/webstore/detail/one-window/papnlnnbddhckngcblfljaelgceffobn
Automatically moves new Windows and Popups as Tab to the Main-Window. 自动将新窗口和弹出窗口作为选项卡移动到主窗口。 So it is never more than a single Window open.
因此,它永远不会超过单个窗口打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.