Jump to content
Larry Ullman's Book Forums

Need To Not Allow Duplicate Child Windows


Recommended Posts

My site includes a parent-window that has a table of customers. By clicking on a customer, the user initiates the opening of a child-window that has a table of further data for that specific customer. Clicking on a customer in the parent-window runs the following code:

 

if(window.varwins["study"+tcustid] && !window.varwins["study"+tcustid].closed){

     alert('A study for this customer, '+tcust+', is already open.');

}

else{

     varwins["study"+tcustid]=window.open("crxindex.php?getcustid="+tcustid,tcustid);

}

 

This works very well. However, if there is a child-window open, and the parent-window is closed, when the parent-window is reopened there is no longer a connection between the 2 windows and the above code does not keep the child-window from being duplicated in a second child-window for the same customer.

 

Is there a way to connect the re-opened parent-window with the already-opened child-window, so that the above code keeps the child-window from being duplicated?

 

I think this all has to do with the same-origin policy, but I need to find a work-around.

 

Thanks.

Link to comment
Share on other sites

Hmmm...interesting one. My question is whether the child window needs a dynamically generated name. Couldn't it always use the same name, which would solve this problem? Or is it likely/necessary that the user may want multiple child windows open at one time?

Link to comment
Share on other sites

  • 3 weeks later...

Yes, it is likely that the user would sometimes want multiple child windows open at one time. For example, while working on customer A in a child window, the phone rings with a call from customer B, so the user opens a second child window, but doesn't want to close the first child window that is in the process of being worked on.

Link to comment
Share on other sites

Hmmm...okay, I don't have a great (i.e., obvious) answer here as it's not an issue I've come across before. My inclination is to use a cookie to store the IDs of open child windows. You'd have to remove the IDs upon closing. Then, if the parent window is closed accidentally, upon re-open it could look at the cookie to see what child windows should exist. What do you think? 

 

Or you could add an event handler to the close event on the parent window that prevents the closing of the parent window should a child window still be open. 

Link to comment
Share on other sites

Both ideas are very helpful, and I think a combination of both may do what I need. I'm not sure exactly how to add an event handler to the close event (which is needed in both ideas). I've had difficulty with that before, but I can figure it out. I'll try it. Thanks!

Link to comment
Share on other sites

 Share

×
×
  • Create New...