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 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    68
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Close the Popup and Refresh the Parent

    Hey guys,

    Been searching on google for two days now, without a valid answer. I'm NEW to javascript, so I need some good help on this haha. I am using the following little piece of code to open a popup window:

    Code:
    <SCRIPT LANGUAGE='JAVASCRIPT' TYPE='TEXT/JAVASCRIPT'>
     <!--
    var win=null;
    function NewWindow(mypage,myname,w,h,pos,infocus){
    if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
    if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
    else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
    settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no";win=window.open(mypage,myname,settings);
    win.focus();}
    // -->
    </script>
    The actual link to open the popup is like this:

    Code:
    <a href="javascript:NewWindow('upload.php','popup','550','252','center','front');">Open the popup</a>
    What I am opening is, an upload page to upload an image (PHP / AJAX). Once the upload is complete and I close the window, I need the parent window (the index page which the link to open the popup is on) to be refreshed, so you can see that the file has been successfully uploaded. Does anyone have a clue how I would fix this?

    If I need to use another code to open the popup, that's fine, I just need help on how to fix this, since I haven't been able to find the answer myself.

    Thanks in advance!
    Last edited by badHabitZ; 12-07-2010 at 06:55 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    You have to do this FROM the popup.

    So where is your code in the popup to close itself?

    Wherever it is, just add in one little line of code:
    Code:
        ...
        opener.location.reload();
        window.close(); // your existing close code...could be self.close() instead
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    badHabitZ (12-07-2010)

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    68
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks, that worked!


  •  

    Posting Permissions

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