繁体   English   中英

window.open 在 IE 中无法正常工作

[英]window.open does not work correctly in IE

我对 IE(测试版本 6 和 8)问题有很大的疑问。 Window.open 方法在 FF、Opera、Chrome 中正常工作。 IE 打开新的 window,但在主 window 中加载相同的 url。 我知道一种解决方案是从href中删除url,但我需要它来关闭JS。 我还需要定位新的 window。

IE“错误控制台”说:访问被拒绝。

<script type="text/javascript">
function regForm()
{
var left = Math.abs((window.innerWidth - 550) / 2);
var top = Math.abs((window.innerHeight - 600) / 2);
window.open("http://somepage.html", "Signin", "width=550,height=600,scrollbars=1").moveTo(left, top);
}           
</script>
<a class="ibm-b1-bttn" href="http://somepage.html" onclick="javascript:regForm(); return false;">Register Now</a>

请帮助我,这对我来说非常重要。 非常感谢!

您可以使用此解决方法来修复它。 先开一个空白的新window,移动它,然后改变位置。 它似乎与 IE 安全问题有关:

锚标签:

<a class="ibm-b1-bttn" href="#" onclick="regForm();">Register Now</a>

JS Function:

function regForm() {
        var left = Math.abs((window.innerWidth - 550) / 2);
        var top = Math.abs((window.innerHeight - 600) / 2);
        var win = window.open("", "Signin", "width=550,height=600,scrollbars=1")
        win.moveTo(left, top);
        win.location = "http://somepage.html";
    }   

您可以尝试在没有 HTTP 的情况下引用 URL 吗? 所以somepage.html\somepage.html取决于文件在您的服务器上的位置?

解开 windows function 调用,看看它实际上给你的是哪一个错误:

var myWin = window.open("http://somepage.html", "Signin", "width=550,height=600,scrollbars=1");
myWin.moveTo(left, top);

window.open 不应该给你这个错误。 我敢打赌这是moveTo?

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM