关闭子级时刷新父级窗口 [英] Refreshing a parent window when closing a child

查看:69
本文介绍了关闭子级时刷新父级窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用window打开一个子窗口.打开
我希望能够在关闭子窗口后刷新父窗口.通过单击窗口右上角的x可以关闭子窗口.我已经尝试过在孩子中这样做:

I am opening a child window using window. Open
I want to be able to refresh the parent window after the child window is closed. The child window is closed by clicking the x on the top right of the window. I have tried to do this in the child:

<body   önunload = "window.opener.location.reload();">



但这不起作用.

有人可以帮忙吗?



But it is not working.

Can anyone please help?

推荐答案



请尝试以下

Hi,

Please try the following

window.close();
if (window.opener && !window.opener.closed) {
window.opener.location.reload();
}



谢谢,
Imdadhusen



Thanks,
Imdadhusen


浏览器窗口的问题之一是无法确定关闭浏览器的方法. (以及子窗口).当然,您可以收听onunload 事件,但是在文档卸载时会被触发.我不知道它在回发期间是否会被触发.许多人都想检查是否是这种情况.

onbeforeunload可能是一个更好听的事件.但是在某些情况下,某些浏览器可能不会触发此事件.我认为Opera是最糟糕的一部.

您可以在页面中添加关闭"按钮吗?如果是这样,那是处理它的肯定方法.但这取决于用户的操作.可以与onbeforeunload
One of the problems with browser window is that there is no sure way of detecting the browser is closing. (that includes child windows as well). Of course you can listen to the onunload event, but get fired when the document is unloaded. I don''t know if it gets fired during postback. You many want to check if that is the case.

May be a better event to listen for is onbeforeunload. But there are cases this event may not get fired by some browsers. I think Opera the worst one.

Can you add a ''Close'' button in your page? If so, that is one sure way to handle it. But that depends on the user action. May combine that with onbeforeunload


这篇关于关闭子级时刷新父级窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆