Jump to content



Photo
- - - - -

Need To Not Allow Duplicate Child Windows

window name duplicate

  • Please log in to reply
6 replies to this topic

#1 shaneg

shaneg

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 14 November 2017 - 10:00 AM

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.


  • 0

#2 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4840 posts
  • LocationState College, PA (USA)

Posted 17 November 2017 - 9:14 PM

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?


  • 0

#3 shaneg

shaneg

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 4 December 2017 - 9:50 AM

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.


  • 0

#4 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4840 posts
  • LocationState College, PA (USA)

Posted 4 December 2017 - 10:07 PM

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. 


  • 0

#5 shaneg

shaneg

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 9 December 2017 - 6:50 PM

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!


  • 0

#6 shaneg

shaneg

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 16 December 2017 - 4:20 PM

The suggested cookie method has been implemented. It works great. Thanks.


  • 0

#7 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4840 posts
  • LocationState College, PA (USA)

Posted 18 December 2017 - 5:34 PM

Oh, fantastic! Thanks so much for letting us know and kudos!!!


  • 0