How To Refresh Greybox Parent Page

Photo of Mike Dalisay
Modified Sunday, December 19, 2010
by - @ninjazhai
I wonder why its hard to find this tutorial on the web. So I decided to make my own. This snippet is useful if you're editing data in the greybox pop up window and then you want to reflect the changes in its parent window by refreshing it.

In case you want to test this code instantly, you may download the code or see the result of this tutorial live:


Step 1: Download Greybox here and place it inside you js/ directory.

Step 2: Create your index.php file, with these codes inside:

          <title>How To Refresh Greybox Parent Page</title>

          <script type="text/javascript">
               var GB_ROOT_DIR = "js/greybox/";
          <script src="js/greybox/AJS.js" type="text/javascript">
          <script src="js/greybox/AJS_fx.js" type="text/javascript">
          <script src="js/greybox/gb_scripts.js" type="text/javascript">
          <link href="js/greybox/gb_styles.css" rel="stylesheet" type="text/css">       

          <script language="javascript" type="text/javascript">
               // we will use greybox' afterclose function to reload the parent page
               // after closing the grebox pop up window
                    function afterclose() {
               // -->


     <b>This is the greybox parent window</b>
          <a href="greybox_pop_up.php" title="Greybox pop up" rel="gb_page_center[500, 500]">
               Click this link to greybox pop up

     Textbox with default input: 
     <input name="sample_textbox" size="40" type="text" value="some predefined value" />


Step 3: Create your greybox pop up page which is greybox_pop_up.php with these codes inside:

          <title>This is the greybox pop up</title>
          <script type='text/javascript'>
          function redirect_to_parent(){
               parent.parent.window.location = "index.php";
<body onunload="redirect_to_parent();"> <-- The important part -->

     <h2>This is the greybox pop up window</h2>
          <input type="button" value="Close This Window" onclick="parent.parent.GB_hide();"> 


Step 4: You should have this files by now:

Final files in this tutorial

Step 5: Testing
  •  If you're gonna run index.php, you should see this in your browser:

Our index.php file

  • Change the predefined textbox value to any values you want, like the following:
Textbox with changed predefined value
  •  Click the link to show the greybox pop up
Greybox pop up window
  • Close the pop up window, if the textbox value returned to "some predefined value", it means that the parent page was refreshed.
By the way, if you're not yet familiar with greybox, I also have a tutorial on how to use greybox. That's it! Hope it helps :)

For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.