DelphiFAQ Home Search:
General :: Web publishing :: JavaScript
Code snippets to add functionality to your HTML pages, preferably cross-browser.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Reload a web page with a javascript function

Question:

I need to force a page reload from a javascript function but document.reload() seems not to work. How do I do it?

Answer:

The document object is not used to reload a window, that is the reason for your problem. Below are three examples, in these cases in the onclick event.

This code will reload the current window. If it is shown in a frame, then only this frame will be reloaded. If you need to reload another frame, then you may want to address it as shown in the last 2 examples.

<input type="button" value="Reload Page" onClick="window.location.reload()">
 
 <input type="button" value="Reload Page" onClick="history.go(0)">
 
 <input type="button" value="Reload Page" onClick="window.location.href=window.location.href">
 
 <input type="button" value="Reload 1st Frame" onClick="window.parent.frames[0].location.reload();">
 
 <input type="button" value="Reload 2nd Frame" onClick="window.parent.frames[1].location.reload();">
 

Generated 0:02:15 on Jul 22, 2017