tags:

views:

34

answers:

1

Using JavaScript

i have the refresh button in my parent window,

when i click refresh button ,

i want to refresh my child window ,

window.location.href='add_billing_order_frm.php?session_re_genrate=new

This snippet redirecting the page instead refresh ,

I thing there is a snippet like

opener.document.location.reload(true);

but this one for parent window refresh, but i want for child window wiht URL location option

function show_billing_order_form(url){
   var childWindow = window.open(url);
}

function refresh_my_child_window(){
   return childWindow.location.reload('add_billing_order_frm.php');
}

To open a popup window(child window) , i used this show_billing_order_form call back ,

To refresh the child window , i add one refresh icon in my parent window , To refresh the child window , in that refresh icon onclick i called refresh_my_child_window ,

but function refreshing my child window..

+3  A: 

When opening your child window from the parent, remember the return value in a variable somewhere:

var childWindow = window.open(/* ... */);

...and when you want to refresh the child:

childWindow.location.reload();

Here's a quick-and-dirty example (live copy):

HTML:

<input type='button' id='btnOpen' value='Open Child'>
<input type='button' id='btnClose' value='Close Child'>
<input type='button' id='btnRefresh' value='Refresh Child'>

JavaScript:

(function() {
  var childWindow;

  document.getElementById('btnOpen').onclick = openChildWindow;
  document.getElementById('btnClose').onclick = closeChildWindow;
  document.getElementById('btnRefresh').onclick = refreshChildWindow;

  function openChildWindow() {
    if (childWindow) {
      alert("We already have one open.");
    }
    else {
      childWindow = window.open('http://jsbin.com/awiri4');
    }
  }

  function closeChildWindow() {
    if (!childWindow) {
      alert("There is no child window open.");
    }
    else {
      childWindow.close();
      childWindow = undefined;
    }
  }

  function refreshChildWindow() {
    if (!childWindow) {
      alert("There is no child window open.");
    }
    else {
      childWindow.location.reload();
    }
  }
})();

Caveat: I would never recommend hooking up event handlers with onclick attributes as above. Instead, I'd use attachEvent (on IE) or addEventListener (on standards-based browsers), by using a library like jQuery, Closure, Prototype, YUI, or any of several others. Used the attributes above to avoid obscuring the main point.

T.J. Crowder