faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

99 of 222 people (45%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

how to call refresh parent window and close child window action through single button in javascript?

Apr 6th, 2008 19:47
ha mo, Dave Clark, Colin Fraser, abhidesh jain,


From the child window, first close the opener, then refresh the current
window:
In a remote *.js file: 
function closeRefresh() {  
    opener.top.close();
    window.location.reload();
}
in the child window : 
<input type="button" value="Close" onClick="closeRefresh()">
I did get this to work in NN4 but IE just did not let it happen. I did
not have the time to find out why then, but I had no complaints either.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     Either the question was confusing or the answer was confused.  
Note the difference between the following two solutions -- the first 
is based on the answer above and the second based on my understanding 
of the question actually asked:
<button type="button" onclick="
 top.opener.top.close();    // close parent window
 top.location.reload(true); // refresh child window
 return true;">Close</button>
<button type="button" onclick="
 top.opener.location.reload(true); // refresh parent window
 top.close();                      // close child window
 return true;">Close</button>
     In both cases, the button is in the child window.  Note that 
closing the parent window is not allowed, without a user prompt (at 
least, not in IE), if the parent window was not created via the 
window.open() method.
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com