简体   繁体   中英

window.close(); not working after window.opener in Firefox

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?

I decided to just close the popup from the parent window

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM