shaneg Posted November 14, 2017 Share Posted November 14, 2017 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 More sharing options...
Larry Posted November 18, 2017 Share Posted November 18, 2017 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 More sharing options...
shaneg Posted December 4, 2017 Author Share Posted December 4, 2017 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 More sharing options...
Larry Posted December 5, 2017 Share Posted December 5, 2017 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 More sharing options...
shaneg Posted December 9, 2017 Author Share Posted December 9, 2017 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 More sharing options...
shaneg Posted December 16, 2017 Author Share Posted December 16, 2017 The suggested cookie method has been implemented. It works great. Thanks. Link to comment Share on other sites More sharing options...
Larry Posted December 18, 2017 Share Posted December 18, 2017 Oh, fantastic! Thanks so much for letting us know and kudos!!! Link to comment Share on other sites More sharing options...
Recommended Posts