当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Parent window is getting closed on refresh

问题描述:

My requirement is that on close of parent window child windows should also close. But now the problem is that even when I refresh my parent window the windows get closed. I dont want that refresh to close the windows. My code is

 function closeEditorWarning(){

for (var i=0;i<childWindow.length;i++) {

if (childWindow[i] && !childWindow[i].closed) childWindow[i].close();

}

self.close();

}

window.onbeforeunload = closeEditorWarning;

网友答案:

On browser refresh page gets unloaded and then it loads again. As you are using "onbeforeunload" it gets called before unload, hence "closeEditorWarning" method is getting called. To resolve this issue you can disable browser refresh.

网友答案:

If the child window is webpage of your own, you may try to put code into child webpages instead, checking if the parent is still there periodically through cookies, seeing if it is kept "alive" or not

网友答案:

I removed self.close(); and it's workng fine now.

分享给朋友:
您可能感兴趣的文章:
随机阅读: