Programming C# C++ (7) Delphi (617) Java (8) JavaScript (31) Document (8) Events (8) ExtJS (9) Strings (3) perl (9) php (4) VBScript (1) Visual Basic (1)
Exchange Links About this site Links to us 
New related comments Number of comments in the last 48 hoursReload a web page with a javascript function 1 new comments
|
Reload a web page with a javascript function
This article has not been rated yet. After reading, feel free to leave comments and rate it.
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();">
| |  | |  |
Comments:
|
anonymous from Brazil
|
|
|
|
very good examples, thank you!
|
2008-06-23, 04:39:43 (updated: 2008-06-23, 04:40:16) |
anonymous from Lebanon
|
|
|
|
very good tip! Thank you keep the good work`
|
|
anonymous from South Africa
|
|
|
|
Syntax:
document.location.reload([bReloadSource]);
Parameters
bReloadSource Optional. Boolean that specifies one of the following values:
- false : Default, reloads the page from the browser cache.
- true : Reloads the page from the server.
|
|
|
|
|
okay, so say you wanted to do this BEFORE another function runs...Example:
<input type='button' value='button' onclick='refreshPage();searchHighlight();'>
where the refreshPage function uses the refresh portion to refresh the current page, then the searchHighlight function searches and highlights a search phrase or the like within the page...and when a user decides to change the search words/phrase then the entire page reloads and the previously highlighted words are no longer highlighted, but the new ones (if found in current page) are...how would this be done?
|
|
|
|
|
Hi, well done. Your tip has been very useful!
|
|