0

I've got the following code in my parent window:

function OpenPopup()   {     
     var authWindow = window.open('t.php', 'authWindow', 'options...');
}

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

And the following code in the pop-up:

 <script type="text/javascript">
function CloseMySelf(sender) {
    try {
        window.opener.HandlePopupResult(sender.getAttribute("result"));
    }
    catch (err) {}
    window.close();
    return false;
}    
 </script>

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

The first part of the function works fine, but the popup doesn't close. I read, that window.close only works if the popup has been opened by javascript, but I thought that was the case here?

window.close works fine, if I remove the opener-function. Is it because the script doesn't know that "window" refers to the child in the second instance?

John Smith
  • 646
  • 1
  • 9
  • 30
  • There may be some useful information: [How can I close a window with Javascript on Mozilla Firefox 3](http://stackoverflow.com/questions/760422/how-can-i-close-a-window-with-javascript-on-mozilla-firefox-3) from another SO question. – tech_me Jan 26 '13 at 13:54

1 Answers1

0

I decided to just close the popup from the parent window

function HandlePopupResult(result) {
    authWindow.close();
    alert("result of popup is: " + result);
}
Pang
  • 9,564
  • 146
  • 81
  • 122
John Smith
  • 646
  • 1
  • 9
  • 30