Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Close popup when I reload parent

    Hello,

    I have read 50 or so posts and keep rewriting (piecing code together) to accomplish one of two things.

    Either 1: Pop open a small window onunload which checks to see if it is on the same domain as the parent window and if so, closes itself.

    or

    2: Pop open the small window onunload. When the parent reloads it closes the popup (onload=close the child window).

    I can get the popups to open just fine, but don't know how to close them when the parent reloads.

    This loads the popup onclick or onunload:
    <script language="JavaScript" type="text/JavaScript">
    <!--
    function MM_closeBrWindow(theURL,winName,features) { //v2.0
    window.close(theURL,winName,features);
    }
    //-->
    </script>

    I've tried amongst 20 other things:
    <body onload="window.close('popup.html')"> in the parent window.

    and in the popup

    <script type="text/javascript">
    function {
    if parent.window.location = "http://www.whatever.com/parent.html";
    "self.close()";
    }
    </script>

    Thanks for any ideas.

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kentucky
    Posts
    133
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok, check this out and see if you can make it work with what you have:

    This would go in the <head></head>:
    Code:
    <script language="JavaScript">
    
    var popupWindow;
    
    function openWin()
    {
    	popupWindow = window.open('http://www.google.com', 'ChildWindow');
    }
    
    function closeWin()
    {
    	popupWindow.close();
    }
    
    </script>
    And you would call closeWin() to close the window in your <body>'s onload event handler:
    Code:
    <body onload="closeWin();">
    The main difference in this code and what you're probably using is that I made popupWindow a global variable. Then inside openWin() I set that variable to window.open, which then gives you a kind of handle on that window. Then all you need to do to close it is call closeWin().

    Hope this helps.


  •  

    Posting Permissions

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