Reputation: 11746
I'm trying to redirect the callback URL back to the parent window that is calling window.open. Currently the callback URL is opening inside the child window spawned from the parent.
Parent Window => Opens child window for authentication => user authenticates and is redirected to this child window. How do I redirect to the Parent Window?
Here is the call to window.open
newwindow = window.open(response.data.auth_url,'Etsy','height=800,width=1000');
if (window.focus) {
newwindow.focus()
}
Any idea how to accomplish this?
Upvotes: 0
Views: 2010
Reputation: 11746
Here's the solution I came up with if anyone else runs into this issue.
In my angularJS Controller file I check for the two pieces of info I need from the callback URL:
if ($state.params.oauth_token && $state.params.oauth_verifier) {
/* This closes the child window */
$window.close();
var params = {
oauth_token: $state.params.oauth_token,
oauth_verifier: $state.params.oauth_verifier
};
/* process the info ... */
}
I also poll to see when the callback URL is made and redirect the parent window
win = window.open(response.data.auth_url,'Etsy','height=800,width=1000');
var pollTimer = window.setInterval(function() {
try {
if (win.document.URL.indexOf(response.data.callback_url) != -1) {
window.clearInterval(pollTimer);
$state.go("etsy.connected");
}
} catch(e) {
// Error Handling
}
}, 500);
Upvotes: 0
Reputation: 1266
To communicate between windows use Postmessage
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Your scenario might be that the child window sends a message to the parent window that in turn closes the child window and redirects to the final url.
Upvotes: 0