简体   繁体   English

IE弹出窗口阻止程序阻止了Javascript window.open

[英]Javascript window.open is blocked by IE popup blocker

Can anyone help, I have a popup that is being blocked. 任何人都可以帮忙,我有一个被阻止的弹出窗口。 It is a popup that is created because somebody has clicked on a Print picture on my site. 这是一个弹出窗口,因为有人点击了我网站上的打印图片。

I thought IE is not supposed to block these when the popup came via an onclick ? 我认为当弹出窗口来自onclick时,IE不应该阻止这些?

Can anyone help? 有人可以帮忙吗? The child1 variable is always returned as NULL if popup blocker enabled... 如果启用弹出窗口阻止程序,则child1变量始终返回NULL

Maybe the problem is that the onclick event then passes control to a new function which loads a html file and does child.document.write 也许问题是onclick事件然后将控制权传递给一个新函数,该函数加载一个html文件并执行child.document.write

Here is my simple code.. 这是我的简单代码..

var width = 800;
var height = 600;
var left = parseInt((screen.availWidth / 2) - (width / 2));
var top = parseInt((screen.availHeight / 2) - (height / 2));
var windowFeatures = "width=" + width + ",height=" + height 
   + ",menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,left=" 
   + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;      

child1 = window.open("about:blank", "subWind", windowFeatures);

The problem will be that open will only return a reference to the window if you are navigating to somewhere within your current host. 问题是如果您导航到当前主机中的某个位置,open将仅返回对窗口的引用。 You are navigating to about:blank which is not within your host. 您正在导航到about:blank,这不在您的主机中。

Try adding a blank.htm file to your site and open that instead. 尝试将blank.htm文件添加到您的站点并改为打开它。 I'm still not sure that document.write will be allowed the document won't be open for write, you may be able to manipulate the DOM of the existing blank document though. 我仍然不确定document.write是否会被允许该文档不会被打开以进行写入,您可能能够操纵现有空白文档的DOM。

The Internet Explorer pop-up blocker, when set to Medium filter level, will not block windows opened by JavaScript if they have been initiated by a user action. 当设置为Medium过滤级别时,Internet Explorer弹出窗口阻止程序将不会阻止JavaScript打开的窗口(如果它们是由用户操作启动的)。 The following works fine in IE 6, 7 and 8: 以下在IE 6,7和8中工作正常:

<script type="text/javascript">
function openWin() {
    var width = 800;
    var height = 600;
    var left = Math.floor((screen.availWidth - width) / 2);
    var top = Math.floor((screen.availHeight - height) / 2);
    var windowFeatures = "width=" + width + ",height=" + height +
            ",menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes," +
            "left=" + left + ",top=" + top +
            "screenX=" + left + ",screenY=" + top;
    child1 = window.open("about:blank", "subWind", windowFeatures);
    writeTo(child1);
}
function writeTo(w) {
    w.document.write('Test');
}
</script>
<a href="#" onclick="openWin();return false;">Test</a>

Note that using document.write into the newly opened window does not work in some web browsers. 请注意,在新打开的窗口中使用document.write在某些Web浏览器中不起作用。 Also note that this may trigger a pop-up blocker in other browsers, even if it works as shown in Internet Explorer. 另请注意,这可能会触发其他浏览器中的弹出窗口阻止程序,即使它的工作原理如Internet Explorer中所示。

I have seen where invoking JavaScript from an onclick event can, in some cases, cause the pop-up blocker to trigger. 我已经看到在某些情况下,从onclick事件调用JavaScript可以导致弹出窗口阻止程序触发。 It seems to have something to do with how far window.open() is from the onclick event. 它似乎有事做多远 window.open()是从onclick事件。 Too many levels of functions calling functions before you call window.open() . 调用window.open()之前调用函数的函数级别太多。 Without seeing your exact implementation, I can't tell you whether this is the problem you are having or not. 如果没有看到您的确切实施,我无法告诉您这是否是您遇到的问题。

It blocks it because it's not an anchor with a target="_blank". 它会阻止它,因为它不是具有target =“_ blank”的锚。 You're creating the popup programatically. 你以编程方式创建弹出窗口。

Just do this after the code example you've provided. 只需在您提供的代码示例之后执行此操作。

if (!child1) {
      alert('You have a popup blocker enabled. Please allow popups for www.yourSite.com');
}

please try code 请尝试代码

var newWin = window.open(...);
if (newWin && newWin.top) {
    // popup has opened
} else {
    // popup has been blocked
}

i have a idea in ie 10/11 : 我有一个想法,即10/11:

let win = window.open();
setTimeout(function(){
    win.customParam = 'xxxx';
});

in win ,you can get customParam after window onload with a timer or loop: 在win中,您可以在使用计时器或循环进行窗口加载后获取customParam:

I suggest you to make a dummy [form] with a target="_blank" instead of a window.open(). 我建议你使用target =“_ blank”而不是window.open()创建一个虚拟[form]。

I hope it works. 我希望它有效。

Regards. 问候。

PD: I suppose adding your site to "trusted sites" is not an option, right? PD:我认为将您的网站添加到“可信站点”不是一种选择,对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 window.open with popup blocker - window.open with popup blocker Javascript window.open()函数打开没有弹出窗口阻止程序的链接 - Javascript window.open() function opens link without popup blocker 如何在使用window.open时停止浏览器弹出窗口阻止程序 - How to stop browser popup blocker when using window.open 如果window.open()被弹出窗口阻止程序阻止,则会回退吗? - Fallback if window.open() is blocked by popup blockers? JavaScript-表单提交到window.open弹出窗口不起作用IE / FF - JavaScript - Form submit to window.open popup not working IE/FF 绕过javascript中window.open()的弹出窗口阻止程序 - Bypassing The pop-up blocker for window.open() in javascript 翻转时在javascript(window.open)中打开一个窗口,而不会被弹出窗口阻止程序阻止 - Opening a window in javascript (window.open) on rollover without getting blocked by popup blockers Javascript onbeforeunload 打开 window.open() 弹出窗口 - Javascript onbeforeunload to open window.open() popup JavaScript怎么打开弹窗? (不是 window.open) - How to open popup in JavaScript? (NOT window.open) 如何使用window.open创建一个不确定延迟的弹出窗口(对于Social Auth)而没有弹出窗口阻止程序阻止它 - How do I create an indeterminately delayed popup (for Social Auth) with window.open without a popup blocker stopping it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM