Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript window.open被IE弹出窗口阻止程序阻止_Javascript_Popup - Fatal编程技术网

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

Javascript window.open被IE弹出窗口阻止程序阻止,javascript,popup,Javascript,Popup,有人能帮忙吗,我有一个弹出窗口被阻止了。这是一个弹出窗口,是因为有人点击了我网站上的打印图片而创建的 我以为IE不应该阻止这些,当弹出窗口通过一个onclick 有人能帮忙吗?如果启用了弹出窗口阻止程序,child1变量始终返回为NULL 可能问题在于onclick事件随后将控制权传递给一个新函数,该函数加载html文件并执行child.document.write 这是我的简单代码 var width = 800; var height = 600; var left = parseInt((

有人能帮忙吗,我有一个弹出窗口被阻止了。这是一个弹出窗口,是因为有人点击了我网站上的打印图片而创建的

我以为IE不应该阻止这些,当弹出窗口通过一个
onclick

有人能帮忙吗?如果启用了弹出窗口阻止程序,
child1
变量始终返回为
NULL

可能问题在于
onclick
事件随后将控制权传递给一个新函数,该函数加载html文件并执行
child.document.write

这是我的简单代码

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

它阻止它,因为它不是带有target=“\u blank”的锚。您正在以编程方式创建弹出窗口

只需在提供的代码示例之后执行此操作

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

问题是,如果您正在导航到当前主机中的某个位置,open将只返回对该窗口的引用。您正在导航到主机之外的约:空


尝试将一个空白的.htm文件添加到您的站点并打开它。我仍然不确定是否允许document.write该文档不会被打开进行写入,但是您可以操作现有空白文档的DOM。

我建议您使用target=“\u blank”而不是window.open()创建一个虚拟[表单]

我希望它能起作用

问候


PD:我想将您的站点添加到“受信任的站点”不是一个选项,对吗?

Internet Explorer弹出窗口阻止程序,当设置为
中等
过滤级别时,如果由用户操作启动,则不会阻止JavaScript打开的窗口。在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>

函数openWin(){
var宽度=800;
var高度=600;
var left=数学地板((screen.availWidth-宽度)/2);
var top=数学楼层((屏幕高度-高度)/2);
var windowFeatures=“width=“+width+”,height=“+height+
,菜单栏=是,工具栏=是,滚动条=是,可调整大小=是+
“left=“+left+”,top=“+top+
“屏幕X=“+左+”,屏幕Y=“+上;
child1=window.open(“关于:空白”,“子风”,windowFeatures);
令状(儿童1);
}
函数写入(w){
w、 文件。编写(“测试”);
}
请注意,在某些web浏览器中,在新打开的窗口中使用
document.write
。还请注意,这可能会在其他浏览器中触发弹出窗口阻止程序,即使它的工作方式与Internet Explorer中所示相同

我已经看到,在某些情况下,从
onclick
事件调用JavaScript可能会触发弹出窗口阻止程序。这似乎与
window.open()
距离onclick事件有多远有关。调用
window.open()
之前调用函数的函数级别太多。没有看到您的具体实现,我无法告诉您这是否是您遇到的问题。

请尝试代码

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

我在ie 10/11中有一个想法:

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

在win中,您可以在窗口加载后使用计时器或循环获取customParam:

是的,谢谢,就是这样,基本上我需要从我当前的web加载一个文件,而不是空白。。。所以我创建了一个空的html文件。。已将其加载并使用windows.write编写我的html。。谢谢大家,谢谢大家的评论