Javascript open new tab, and wait for it to close

后端 未结 3 1483
故里飘歌
故里飘歌 2021-02-19 19:02

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

when the user is back from the bank payment to a

3条回答
  •  礼貌的吻别
    2021-02-19 19:42

    You can open a new page using window.open and then check periodically to see if the window has been closed. The reference to the opened window is returned by window.open and you can check if it has been 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 info on window.open and best practises, take a look at MDN.

提交回复
热议问题