Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 13-Feb-11 16:53pm
v2

Hi,

Please try the following

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


Thanks,
Imdadhusen
 
Share this answer
 
Comments
flomm 14-Feb-11 12:11pm    
If I use this and do something on the child window, for example select something from a drop down or click on a button, then it closes the child window. I don't want it to do that. Is there something else I could do?
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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900