Results 1 to 3 of 3

Thread: How to close a popup window on closing some other window

  1. #1
    Join Date
    Jun 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to close a popup window on closing some other window

    My problem is little peculiar.
    Parent1.jsp opens a popup window Popup1.jsp which opens another popup Popup2.jsp. As soon as Popup2.jsp is opened, Popup1.jsp closes itself.

    Now I need to close Popup2.jsp when Parent1.jsp is closed.

    using Window.opener doesn't work because then as soon as Popup1 is closed, Popup2 is also closed.

    Can anyone please tell me how to do this?

    Thanks.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    When you open the second pop up, you could assign it as the value of a variable on the original parent (the page that will, presumably still be open, Parent1.jsp from your post).

    So on Popup1.jsp, when you open Popup2.jsp, you could do it something like:

    Code:
    window.opener.pop2 = window.open('Popup2.jsp');
    That way, even after Popup1.jsp is closed, on Parent1.jsp you can do:

    Code:
    window.onunload = function(){
    if(typeof pop2 != 'undefined')
    pop2.close();
    }
    To close it when Parent1.jsp closes. Opera doesn't usually (maybe never) fire onunload though - just a warning, almost all others do. Also, there will be a fleeting error reported in some browsers if pop2 is already closed. The usual sorts of things (if you are opening and closing pop ups you probably know about them) could be done to prevent that.
    Last edited by jscheuer1; 06-18-2008 at 07:37 AM. Reason: fix typo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jun 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default It works!

    Thanks a lot.

    This works fine. Just a small change:
    Code:
    window.opener.pop2 = window.open('Popup2.jsp');
    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •