I need to close child windows which has been loaded by a parent window.
The child windows are opened by using window.open() method.
I need to close this child windows by clicking a logout button or close button which is in parent window.
My code:
var childWin = [];
//child window open event
function child_open(url)
{
childWin[childWin.length] = window.open(url);
}
//a logout button or close button event
function parent_close()
{
for (i=0; i<childWin.length; i++)
{
if (childWin[i] == null) return false;
childWin[i].close();
}
window.close();
}
This code is OK if the parent window don’t postback to server.
When a postback occured in parent window,the value of variable(childWin) disappeared and I can’t close child windows by this code.
Problem is – want to close child windows even the parent postbacked.
Is there a solution for this?
Thanks for all of your interests and replies.
Your array childWin will be cleared each time the page is loaded. So after post back there will be nothing in the array. Thats why the child windows are not getting closed.
A work around is mentioned here
Try something like this [not tested, and not sure it will work , just give a try 🙂 ]
Parent Window (all pages)
Child Window
Your Child window open function
Your close button event
Possible fix for query >> But, after a postback of child ,an error occurs in parent_close() (the value in childStatus[key] is not object and it can not do childStatus[key].close())
Replace
with