Javascript will open a new tab and wait for it to close

I want to open a new tab for bank payment on my website using javascript, and without the main navigation window,

when a user returns from a bank payment to a return URL, I want to determine the response of the return URL from another window (if possible) or simply notify the main window that the transaction has been completed, and it should check the database for updates.

I have seen this behavior on several sites, such as popup->login->popup closes->main window reloads with a loaded session. The problem is that I don’t know how this method is called, so I don’t know what keyword I am looking for.

I only need the name of this method or how to do it (as a specific keyword in javascript or something else)

Thanks in advance

+7
source share
2 answers

Before closing the popup, try opener.someFunction() call the function in the window that opens. Please note that this will not work if the user has closed the first window or the user has switched to another site or if for some reason both windows are located on different domains.

+2
source

You can open a new page with window.open , and then periodically check if the window is closed. The link to the open window is returned by window.open , and you can check if it was closed using windowHandle.closed .

 btn.onclick = function() { var win = window.open( "http://www.stackoverflow.com", "Secure Payment"); var timer = setInterval(function() { if (win.closed) { clearInterval(timer); alert("'Secure Payment' window closed !"); } }, 500); } 

See also this short demo .

For more information on window.open and best practices, check out MDN .

+6
source

All Articles