Reputation: 1023
I want to achieve the following behaviour in my application:
1) I open a popup from a web page in my application wich shows a new .aspx web page.
2) From this popup another popup might be generated which opens another .aspx web page.
3) From my web page when I press a button I want to close the popup I generated (no problem with this) and the popup that the popup generated if they have not been closed by user.
I think this could be done either by having a application global variable in javascript (I mean one that could be accessed from any aspx file) or maybe there's some function that gives a reference to the created popups but I don't find it.
The most I've managed to do is to create a global variable in the first popup window that references the new popup, but if I try to close it from my parent window it gives an error, as it tries to search that global variable in the ones that it has defined and obviusly doesn't find it.
Any idea on how to achieve this? Thank you.
Upvotes: 1
Views: 99
Reputation: 3719
According to an answer on experts-exchange.com:
in the window that opens the grandchild try:
window.opener.w = window.open("newpage.htm");
now you can close the grandchild from the main window using w.close()
So, the first child window assigns the variable to it's parent so the parent has reference to the grandchild.
Upvotes: 2
Reputation: 1185
You could add an onunload
event to the body in the first popup window that will close the second window when the first one is closed itself.
So the code that opens the second popup might look like this:
var popup_window = window.open('...');
A function to close it would be
function close_child_window()
{
popup_window.close()
}
And for the onunload
event in the first popup's body,
<body onunload='close_child_window();'>
Upvotes: 1