简体   繁体   English

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

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

i have a big problem with IE (tested versions 6 & 8) issue.我对 IE(测试版本 6 和 8)问题有很大的疑问。 Window.open method works correctly in FF, Opera, Chrome. Window.open 方法在 FF、Opera、Chrome 中正常工作。 IE opens new window, but loads the same url in main window. IE 打开新的 window,但在主 window 中加载相同的 url。 I know one solution can be to remove url from href, but i need it for JS turn off case.我知道一种解决方案是从href中删除url,但我需要它来关闭JS。 Also i need positioning for new window.我还需要定位新的 window。

IE "error console" says: Access denied. 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>

Please help me, this is very important for me.请帮助我,这对我来说非常重要。 Thanks a lot!非常感谢!

You can use this work around to fix it.您可以使用此解决方法来修复它。 First open a blank new window, move it, then change the location.先开一个空白的新window,移动它,然后改变位置。 It appears to have something to do with IE security issues:它似乎与 IE 安全问题有关:

Anchor Tag:锚标签:

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

JS Function: 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";
    }   

Can you try referencing the URL without the HTTP?您可以尝试在没有 HTTP 的情况下引用 URL 吗? so somepage.html , or \somepage.html depending on where the file resides on your server?所以somepage.html\somepage.html取决于文件在您的服务器上的位置?

Unchain the windows function calls and see which one it's actually giving you the error on:解开 windows function 调用,看看它实际上给你的是哪一个错误:

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

window.open should not give you that error. window.open 不应该给你这个错误。 I'm betting it's the moveTo?我敢打赌这是moveTo?

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

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