StackOverflow_17171589: javascript-open-new-tab-and-wait-for-it-to-close

Illustration of answer to http://stackoverflow.com/questions/17171589/javascript-open-new-tab-and-wait-for-it-to-close.

by ExpertSystem

HTML

<div id="info">
    Click to be tranfered to our secure blah blah blah (a.k.a. PAY)
    <button id="goPay">Pay</button>
</div>

JavaScript

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

var div = document.getElementById("info");
function paid() {
    info.innerHTML = "Seems like you have completed payment !<br />Let me check the DB...";
}