Javascript Window Location Reload or Refresh Function
Javascript location reload function of DOM window object provides the functionality to reload or refresh the current web page. You can create function having the code to run the location.reload function onclick event of button control or any other HTML element that supports mouse events to call Javascript function. Location reload function refreshes the currently open web page. Do not place the window.location.reload() function openly in the Javascript block placed in the HTML <head> section of HTML document. It will set it into infinite loop of redirecting the same page at its own URL on page load coz each time when page will load. It will fire the location.reload function causing the infinite loop of reloading the same URL again and again.
JavaScript Window Location Object Examples:
You can see the live samples and examples of JavaScript Window Location Object from the following links:
Syntax of Javascript Window Location Reload or Refresh Function
location.reload();
or
window.location.reload();
Both code syntax to reload or refresh the current page using window object or without window object will work similarly.
Example of Javascript Window Location Reload or Refresh Function
<script type="text/javascript" language="javascript">
function reloadURL() {
window.location.reload();
}
</script>
Call the above reloadURL() function onclick event of button control:
<input type="button" value="Refresh Location URL" onclick="reloadURL();" />
Output:
You can see the output of above discussed code from the following link:
Continue to next tutorial: Javascript Window Location Href URL to learn how to redirect the get or set the current URL using JavaScript.
