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.
You 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: