每次加载页面时,您的数组 childWin 都会被清除。因此,在回发后,数组中将没有任何内容。这就是为什么子窗口没有关闭的原因。
这里提到了一种解决方法
尝试这样的事情[未经测试,不确定它会起作用,试一试:)]
父窗口(所有页面)
var childStatus = {};
子窗口
var timerHandler,
windowName = window.name,
popupHandle = "";
funciton ChildCallBack()
{
try
{
if(popupHandle == "" || popupHandle == null)
{
popupHandle = window.opener.childStatus[windowName];
//ChildCallBack(); // no need of ChilCallBack here, since we already have timer
}
else
{
window.opener.childStatus[windowName] = popupHandle;
}
}
catch(e)
{
}
}
timerHandler = window.setInterval(ChildCallBack, 500);
function window_onclose()
{
try
{
window.clearInterval(timerHandler);
window.opener.childStatus[windowName] = null;
}
catch(e)
{
}
}
window.onclose = window_onclose;
Your Child 开窗功能
//child window open event
function child_open(url)
{
var winHandle = window.open(url, "GIVE SOME UNIQUE NAME FOR EACH WINDOW HERE");
winHandle.popupHandle = winHandle;
}
你的关闭按钮事件
//a logout button or close button event
function parent_close()
{
for (var key in childStatus)
{
if (childStatus[key] != null)
{
childStatus[key].close();
}
}
window.close();
}
查询的可能修复>> 但是,在回发 child 后,在 parent_close() 中发生错误(childStatus[key] 中的值不是对象,它不能执行 childStatus[key].close())
代替
timerHandler = window.setInterval(ChildCallBack, 100);
和
if(popupHandle == "" || popupHandle == null)
{
// get the popupHandle from parent window
popupHandle = window.opener.childStatus[windowName];
timerHandler = window.setInterval(ChildCallBack, 100);
}