Popup window to return data to parent on close

In the calling (parent) window add such JS code:

function HandlePopupResult(result) {
    alert("result of popup is: " + result);
}

In the child window code add this:

function CloseMySelf(sender) {
    try {
        window.opener.HandlePopupResult(sender.getAttribute("result"));
    }
    catch (err) {}
    window.close();
    return false;
}

And have such links to close the popup:

<a href="#" result="allow" onclick="return CloseMySelf(this);">Allow</a>
<a href="#" result="disallow" onclick="return CloseMySelf(this);">Don't Allow</a>

Leave a Comment