新窗口无法在Chrome中打开 [英] new window doesn't open as tab in Chrome

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

问题描述

我为Chrome构建了一些



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



由于某些不明的原因,我只找到关于反对。
我如何实现这一目标?

如果在这种情况下,我怎样才能在没有Chrome浏览器屏蔽它的情况下调用编程选项卡开头?

编辑:
我看到一些帖子说这是不可能的,那是它的浏览器偏好。
首先,我不知道如何设置该偏好!
其次,我看到有人声称他们这样做了,所以谁相信?


编辑2:
我发现Chrome会打开新窗口并且不会打开标签,因为它是一个JavaScript窗口打开,而不是用户点击。
任何人都知道我可以伪造真正的点击?
因为调用click事件仍然算不上用户点击

解决方案

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



你可以做什么,尽管它是一个非常糟糕的黑客行为,用户操作,然后使用稍后对弹出框的引用将该位置设置为最终目的地,如下所示:

 < 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);


I'm building something ONLY for 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?

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

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. 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天全站免登陆