Listen to the child window close event in Oauth Like Situation [jQuery | Javascript]

I am using oAuth 1.0 to access third-party data.

To do this, I do the following steps: -

  • The user clicks the "sync with third party" button. (The user must click because this usually does not cause a popup blocker.)

  • When the user clicks on this button, the 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 a new window, PHP receives a third-party authentication URL, then redirects the user to the same URL. As soon as the user redirects to a third party above, he says that "the child window is closed."

  • Then the user visits a third-party site (if necessary) and provides access to our application. As soon as he clicks the "Allow" button, a third party redirects the user to a new page on our website. On this page, I call the window.close () method, which works fine.

  • But in window.close () in the child window, the parent window cannot know that the child is closed.

How can I solve this problem?

Note. This third one does not like Iframe and is updated to open it in the upper window. I have no control over third-party content. Our web page is in HTML5 format.

+4
source share
1 answer

You cannot access the contents or events of the child window, as there are problems with the rights to it in Javascript.

Well, if something is in the same domain, you should try once to do document.domain the same thing in both windows.

as:

 var hdomain="yourdomain.com"; if (document.domain != hdomain){ if ((document.domain.indexOf(hdomain)) != -1){ document.domain = hdomain } } 

put this on both the parent and child’s pages.

Good luck.

0
source

All Articles