window.open 返回 true 时始终关闭

发布于 2024-11-06 06:20:36 字数 1584 浏览 0 评论 0原文

在 IE9 上,window.open() 始终返回 true 关闭的属性。这是我在 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 上发现了这个错误: 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() 在第二次调用时返回未定义或 null

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

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) 
            { }
   }

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.

I also try the following code:

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

which I find here: window.open() returns undefined or null on 2nd call

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦罢 2024-11-13 06:20:36

open() 是 window 的一种方法,因此在非严格比较中它将始终评估为 true。您想查看弹出窗口的 close 属性,请使用以下内容(已编辑,抱歉,我第一次没有正确回答您的问题):

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文