I have been searching high and low for a solution to my problem and can only find pieces of the puzzle with no way to connect them. I have a window (which it self is a child of the main window) that can open multiple other windows. I want the children windows to be closed when the parent is closed, sounds simple enough right?
Here is the dilemma, my parent window does a postback when opening the child so any array of handles (which are also objects) I keep does not persist. I have looked into serializing and de-serializing this array and storing it in a hidden field but that doesn't seem like the best solution. I also can not access the parent of the window doing the opening.
Aside from Javascript, the server side code is written in C# and I'm using asp.net. Is there any reasonable solution to this? I should also mention that the code I am working with was written by multiple different people long before I got to it so I would like to add to it rather than changing how most of it works.
Finally, I know it is typically a good idea to post my code on here but I am simply using var win = window.open
to perform the window opening task.
Thank you.
What about
var wins = [];
function newChildWindow(...) {
wins.push(window.open(...));
}
window.onuload = function() {
for (var i=0; i<wins.length; i++)
if (!wins[i].closed)
wins[i].close();
};
OK, I then see 3 ways to get around that problem:
window.open
with the same target (name) will use the already open one. With that, you can reference windows you didn't open yourself - and close them. See https://stackoverflow.com/a/563478/1048572
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.