Monday, December 8, 2008

Communicate data between two browser windows

To communicate data between two browser windows "window.opener" can be of assistance. window.opener returns a reference to the window that opened the current window. So this mock function below should be inserted into the opened window.
Make note that "__datatarget" and "__datawindow" are two variables that were defined in the parent window.

function SetData(data)
{
  if ((window.opener != null)
  && (!window.opener.closed)
  && (window.opener.__datatarget != null))
  {
    var changed = (window.opener.__datatarget.value != data);
    window.opener.__dataetarget.value = employee;
    window.opener.__datawindow.value = null;
    if (changed)
      window.opener.__datatarget.fireEvent("onchange");
  }
window.close();
}

No comments: