0

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.

Community
  • 1
  • 1
elranu
  • 2,292
  • 6
  • 31
  • 55

1 Answers1

0

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>
RobG
  • 142,382
  • 31
  • 172
  • 209
  • It does not work :( the check status button always return null. On www.myspace.com you can see it works. I do not know yet how.You click th fb button, opens a popup. And when it close, the opener window redirects. – elranu May 12 '11 at 03:06
  • The above code runs fine in Firefox and IE 6, I don't have IE 9 for testing. – RobG May 12 '11 at 03:14