Check if a popup window is closed

后端 未结 4 1296
旧巷少年郎
旧巷少年郎 2020-11-29 11:34

I am opening a popup window with

var popup = window.open(\'...\', \'...\');

This javascript is defined in a control. This control is then

相关标签:
4条回答
  • 2020-11-29 11:43

    Try this:

    window.opener.location.reload(true);
    

    or

    Into the popup before closing

    window.opener.location.href = window.opener.location.href;
    window.close();
    
    0 讨论(0)
  • 2020-11-29 11:44

    Instead you should use a modal dialog like so

    var popup = window.showModalDialog("page.html", "", params);
    

    This would stop your at this line until the dialog is closed.

    Somewhere in your page.html you would then code some javascript to set the window.returnValue which is what will be place the the popup variable.

    Update

    Window.showModalDialog() is now obsolete.

    0 讨论(0)
  • 2020-11-29 11:45

    Ok so what you do is as follows.

    create a method "setWindowObjectInParent" then call that in the popup. var popupwindow;

    function setWindowObjectInParent(obj)
    {
    popupwindow = obj;
    }
    

    Now you have an object that you can call focus on.

    So in the popup add

    $(window).unload(function(){
    window.opener.setWindowObjectInParent();
    });
    window.opener.setWindowObjectInParent(window);
    

    This will unset the obj when the popup is closed and set the object when it is opened.

    Thus you can check if your popup is defined and then call focus.

    0 讨论(0)
  • 2020-11-29 12:08

    Here's what I suggest.

    in the popup you should have:

    <script type="text/javascript">
    
    function reloadOpener() {
      if (top.opener && !top.opener.closed) {
        try {
          opener.location.reload(1); 
        }
        catch(e) {
        }
        window.close();
      }
    }
    window.onunload=function() {
      reloadOpener();
    }
    </script>
    
    <form action="..." target="hiddenFrame">
    </form>
    <iframe style="width:10px; height:10px; display:none" name="hiddenFrame" src="about:blank"></iframe>
    

    then in the server process return

    <script>
       top.close();
    </script>
    

    Old suggestions

    There is no variable called popup in the popup window. try

    var popup = window.open('...','...');
    if (popup) {
      popup.onclose = function () { opener.location.reload(); }
    }
    

    or with a test:

    popup.onclose = function () { if (opener && !opener.closed) opener.location.reload(); }
    

    PS: onclose is not supported by all browsers

    PPS: location.reload takes a boolean, add true if you want to not load from cache as in opener.location.reload(1);

    0 讨论(0)
提交回复
热议问题