2

Is it possible to track a child window if the parent page is reloaded?

I currently open the window like so:

  var childWindow;
  childWindow= window.open('url...');

and when I want to reopen the same child window I do

 childWindow.focus();

The obvious problem is that if the parent window is refreshed then it loses track of the childWindow and can't focus it. Is there any way to get my reference to the child window back?

Mr. Flibble
  • 26,564
  • 23
  • 69
  • 100

2 Answers2

2

Maybe you could use the name parameter (second one) used in window.open() to "reload" your popup when the parent window reloads... ?

Golmote Kinoko
  • 898
  • 5
  • 8
  • Sorry to be a simpleton, but what `name` parameter do you mean? Could you add an example/meta code? – Mr. Flibble Sep 24 '10 at 17:34
  • 1
    The `open()` method can take three parameters. First one is the URL, second one is the name of the popup, and third one is the options. If you use open() twice with a same popup name, the first call will open a popup to display the first URL, the second call will reload the popup to display the second URL in the same window. So maybe you could use the same popup name every time to keep track of your window ;) – Golmote Kinoko Sep 25 '10 at 05:01
0

As mentioned above. I did not find the way how to get from parent window object its child windows. Probably nothing like window.childWindows array or method exists. After reloading parent page you even lost all binding created with javascript like childWindow = window.open(url,'myChildWindow',opt)

Only possible way I found for FF 3.x is in case you know the name of child window you are looking for. In this case open window again with the same name and if it is still open you should get the lost link. In other case the new window is open. lostWindow = window.open('','myChildWindow','');

Now you have to test if it is your old window or the new one. For example by some attribute you registered in your child window.

if (lostWindow.myProperty == 'yes') you can be quite sure it is your lost window.

As I was looking through internet i found some people try to create workaround with cookies or in HTML5 with applicationCache.

vgoff
  • 10,980
  • 3
  • 38
  • 56
user904559
  • 11
  • 2