I am using oAuth 1.0 to access 3rd party data.
For this I am taking following steps :-
User clicks on "sync with 3rd party" button. ( It is necessary for user to click because this usually doesn't invoke popup blocker.)
When user click on this button following code is executed :
$('#sync_with_thirdparty').click(function(){
var child = window.open('/oauth');
$(child).unload(function() {
if (this.location != "about:blank") {
alert("Child window closed");
}
});
});
Now in the new window PHP get the authentication URL from 3rd party then it redirects the user to the same URL. As soon as user redirects to 3rd party above code says that "child window closed.".
Then user makes himself login on third party site (if necessary) and gives access to our app. As soon as he clicks on allow button third party redirects the user to a new page in our website. On this page I am calling window.close() method which is working perfectly fine.
But upon window.close() in child window, parent window is not able to know that child is closed.
How I can solve this problem?
Note : This 3rd doesn't like Iframe and refreshes itself to open in top window. I don't have any control over 3rd party's content. Our webpage is in HTML5 format.
The child window can communicate with the parent window via the window.opener()
function. You could do something like this:
Child window
window.opener.messageFromChildWindow('closed');
Parent window
function messageFromChildWindow(msg) {
if(msg === 'closed') {
alert('child window closed');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With