window.open返回始终关闭true [英] window.open returns always closed in true

查看:157
本文介绍了window.open返回始终关闭true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

window.open()总是返回true,在IE9上关闭。这是我在Facebook上的oAuth的代码:

window.open() returns always the porpertie closed in true, on IE9. This is my code to oAuth on Facebook:

 $(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上发现了这个错误:
http:// support .microsoft.com / kb / 241109 ,但工作arround不起作用。因为window.opener.childOpen总是返回null。

I found this bug on msdn: http://support.microsoft.com/kb/241109 , but the work arround does not work. Because window.opener.childOpen always returns me 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()在第二次调用时返回未定义或空值

编辑: http://www.myspace.com 在IE上工作。我不明白他们是怎么做到的。

on http://www.myspace.com works on IE. I do't understand how they do it.

推荐答案

open()是一种窗口的方法,总是在非严格比较中评估为 true 。你想查看弹出窗口的关闭的属性,播放以下内容(编辑,对不起,我没有第一次正确回答你的问题):

open() is a method of window, so it will always evaluate to true in a non-strict comparison. You want to look at the closed property of your popup, play with the following (edited, sorry, I didn't answer your question correctly the first time):

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

这篇关于window.open返回始终关闭true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆