IE9写入窗口时出现“Permission Denied”错误 - ExtJS 4应用程序

3
var display_setting = "toolbar=yes, location=no, directories=yes, menubar=yes,";
    display_setting += "scrollbars=yes, width=750, height=600, left=100, top=25";
    var printwin = window.open('', 'printwin', display_setting )
    printwin.document.open()
    printwin.document.write("Testing")
    printwin.document.close()

为什么上面的代码在IE9中会生成“权限被拒绝”错误,但在Firefox或Chrome中完全正常?有解决方法吗?这是一个在单个域从内联网运行的ExtJS 4.1应用程序。它使用了可能是一个因素的ExtJS历史功能。谢谢

在我的工作中。但是无法关闭。 - Akhil Sekharan
5个回答

4
我已经测试了上面的代码,在IE中我只发现了一个问题,就是在最后一行你没有声明win对象...如果你提供你的需求细节,我可以帮助你。我修改了你的代码并尝试了它在IE中工作得很好。
这里是测试代码。如果你想关闭窗口,请使用printwin.close()而不是printwin.document.close()
<script type="text/javascript">
function openwindowIE(){
var display_setting = "toolbar=yes, location=no, directories=yes, menubar=yes,";
    display_setting += "scrollbars=yes, width=750, height=600, left=100, top=25";
    var printwin = window.open('', 'printwin', display_setting )
    printwin.document.open()
    printwin.document.write("Testing")
    printwin.document.close()
}
</script>
<input type="button" onclick="openwindowIE()" value="go"  />

是的,我认为这一定与内部网站有关,它使用了ExtJS 4.1。可能会以某种我看不到的方式产生干扰。 - BigBadOwl

1

试一下这个:

var display_setting = "toolbar=yes, location=no, directories=yes, menubar=yes,";
display_setting += "scrollbars=yes, width=750, height=600, left=100, top=25";

var printwin = window.open('about:blank', 'printwin', display_setting);

printwin.document.open();
printwin.document.write("Testing");

printwin.close();

测试


请查看此链接 https://dev59.com/z2435IYBdhLWcg3wigux 和此链接 http://forum.jquery.com/topic/strange-behaviour-in-ie9#14737000002672231。 - andres descalzo

1
这可能有点冒险,但您是否关闭了所有IE窗口并进行了测试?我考虑的可能性是,在测试时,您可能已经打开了一个名为printwin的窗口,然后导航离开了基础页面(或在新标签页中打开它或尝试打开多个名为printwin的窗口),现在又想要打开具有名称printwin的窗口。 printwin窗口已经打开,但基础页面没有权限访问它,因为它不是该页面的原始打开者
关键点在于窗口名称应始终是唯一的

1
如果我没记错的话,IE认为你试图打开的about:blank是一个不安全的网站,因此你无法与它通信。
如果我没记错的话,你可以打开任何其他(空)HTML文档并在其中编写。

实际上,错误从“权限被拒绝”变成了“访问被拒绝”。 - BigBadOwl
是的,听起来IE8的安全策略更差。我不知道怎么修复它。 - looper

0
经过所有这些,结果发现其中一个包含的脚本包含了该行


document.domain = document.domain;

移除后,一切都正常运作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接