Link to home
Start Free TrialLog in
Avatar of sy_geoffrey
sy_geoffreyFlag for Philippines

asked on

need to determine if popup is loaded

Here's the situation,
I have a window(lets call this the parent window) which displays a set of images. The user can popup a window(child window) to get a better display of the images. Now, the user has an option to close the parent window and open another one(this will become the new parent window) to display another set of images without closing the child window. With this, the child window must also be refreshed in order to load the same set of images. The thing is, these 2 windows must be synchronized, so i need to change the reference of the parent in the child window. Im doing something like this:

// in the parent window
var win = window.open(url,name);
win.setParent(window);

//in the child window
var parentWindow = null;
function setParent(win){
     parentWindow = win;
}

The code works fine.. BUT the problem is when the child window takes long time to refresh, the parentWindow becomes null. I think that's because win.setParent(window) has been executed while child window is still loading. Obviously, i must call setParent() right after the child window is finish loading. So I've tried something like this in the parent window:

var win = window.open(url,name);
win.document.body.onload = childOnload;
function childOnload(){
   win.setParent(window);
}

But this code doesn't seem to work. Is there any other way to determine if popup window has been loaded?Or am I missing something on that code? Btw, I've also tried win.onload = childOnload; and didn't work.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Closing windows won't work out for you well.. Especially if your users are using IE7... If you really want to change data on the fly. I would really recomend using Ajax to build your data on both pages; completly eliminating the need for much of this hassel and page reloads...

Check Out The Yahoo! User Interface Library (YUI) - http://developer.yahoo.com/yui/
You could take it a step further and do what I would prefer and not do a pop-up window at all. But instead populate a  div on the pag with absolute positioning that you display/hide on command that is on top of everything else... Doing a psuedo pop-up without all the problems of multiple windows...
Avatar of sy_geoffrey

ASKER

thanks mp...

your solution really worked.. there is no need to refresh the child window, i can change the reference of the parent in the child with you solution.

thanks a lot.
So why a "B" grade?