admin管理员组文章数量:1356354
Here's my scenario:
I'm opening a window from a javascript file, and setting an interval to check whether that window has been closed or not. (this acts as a callback function of sorts).
The problem is, the window I'm opening is to a page that contains a redirect. So I somehow need a way to have the window close itself after the redirect has taken place (so the callback can be triggered).
Script that opens the window:
oauthWindow = window.open("login/index.php", "Login", options.windowOptions);
oauthInterval = window.setInterval(function() {
if (oauthWindow.closed) {
window.clearInterval(oauthInterval);
options.callback();
}
}, 1000);
The page that's being opened will redirect itself:
$url = $oauth->getAuthorizeURL($request['oauth_token']);
header("Location: " . $url);
I need a way for the window to close itself after that redirect has occurred. (window.close());
Any ideas?
Thanks.
Here's my scenario:
I'm opening a window from a javascript file, and setting an interval to check whether that window has been closed or not. (this acts as a callback function of sorts).
The problem is, the window I'm opening is to a page that contains a redirect. So I somehow need a way to have the window close itself after the redirect has taken place (so the callback can be triggered).
Script that opens the window:
oauthWindow = window.open("login/index.php", "Login", options.windowOptions);
oauthInterval = window.setInterval(function() {
if (oauthWindow.closed) {
window.clearInterval(oauthInterval);
options.callback();
}
}, 1000);
The page that's being opened will redirect itself:
$url = $oauth->getAuthorizeURL($request['oauth_token']);
header("Location: " . $url);
I need a way for the window to close itself after that redirect has occurred. (window.close());
Any ideas?
Thanks.
Share Improve this question edited Jan 8, 2012 at 0:03 BartekR 3,9873 gold badges27 silver badges33 bronze badges asked Jan 7, 2012 at 22:27 NickNick 1,2775 gold badges31 silver badges46 bronze badges 2-
Well, you could do a
$.ajax()
call to get the new url, then redirect from the page itself. – Jared Farrish Commented Jan 7, 2012 at 22:41 - Do you have access to modify the login page and the page it redirects to? I'm thinking if this is the case you could pass a querystring flag to the login page and then the login page to the redirect page so when such page loads it closes itself immediately. – epignosisx Commented Jan 7, 2012 at 22:55
1 Answer
Reset to default 4You could check the window.location.href of the newly open window and whenever it is different from the login page you know that the redirect has taken place and it is safe to close it. Here is an example:
var win = window.open("/login/index.php", "Login");
var id = setInterval(function () {
if (win.location.href.indexOf("/login/index.php") < 0) {
clearInterval(id);
//ready to close the window.
}
}, 500);
本文标签: javascriptClose windowafter redirectStack Overflow
版权声明:本文标题:javascript - Close window, after redirect - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744060829a2584091.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论