window.open()总是在IE9上返回以true结尾的porpertie。这是我在Facebook上oAuth的代码:
$(window).ready(function(){
$("#linkFacebook").click(LoginFb);
});
var winInter;
var win;
function LoginFb(){
var linkFB = '@Url.Action("LogOn", "Facebookk")';
win = window.open(linkFB, 'FB', 'toolbar=0,scrollbars=1,status=1,menubar=1,location=0,resizable=1,width=560,height=500');
winInter = setInterval(checkWindow, 1000);
}
function checkWindow()
{
try {
if (win.closed)
{
clearTimeout(winInter);
window.location.href = "@Url.Action("Index", "User")";
}
}
catch (e)
{ }
}
我在msdn上发现了这个bug: http://support.microsoft.com/kb/241109,但工作无效。因为window.opener.childOpen总是返回null。
我也尝试以下代码:
var WindowRef = null;
function openWindow(url, name, props) {
if(WindowRef == null){
WindowRef = window.open(url, name, props)
}
else{
WindowRef.document.location = url
}
if (!WindowRef.opener) {
WindowRef.opener = self;
}
WindowRef.focus();
return WindowRef;
}
我在这里找到:window.open() returns undefined or null on 2nd call
编辑:http://www.myspace.com在IE上工作。我不明白他们是怎么做到的。
答案 0 :(得分:0)
open()
是一种窗口方法,因此在非严格比较中它总是会评估为 true 。你想查看弹出窗口的closed
属性,玩下面的内容(编辑,对不起,我第一次没有正确回答你的问题):
<script type="text/javascript">
var win;
function popWin(url) {
if (win && !win.closed) {
win.location.href = url;
} else {
win = window.open(url,'PopUp');
}
return win;
}
</script>
<button onclick="popWin('http://www.google.com');">Open new window</button>
<button onclick="alert(win && win.closed);">Check if closed</button>
<button onclick="win && win.close();">Just close</button>
<button onclick="win && win.close(); win = undefined;">
Close and remove reference</button>
<br>
<button onclick="popWin('http://www.apple.com');">Change URL</button>