window.open returns always closed in true
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.focu开发者_如何学运维s();
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.
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>
精彩评论