Tutorials Point


  JavaScript Basics
  JavaScript Objects
  JavaScript Advanced
  JS Useful References
  JS Useful References
  JS Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

JavaScript - Page Refresh


previous next AddThis Social Bookmark Button


Advertisements

You can refresh a web page using JavaScript location.reload method. This code can be called automatically upon an event or simply when the user clicks on a link.

If you want to refresh a web page using a mouse click then you can use following code:

<a href="javascript:location.reload(true)">Refresh Page</a>

To understand it in better way you can Refresh Page.

Auto Refresh:

You can also use JavaScript to refresh the page automatically after a given time period. Following is the example which would refresh this page after every 5 seconds. You can change this time as per your requirement.

<html>
<head>
<script type="text/JavaScript">
<!--
function AutoRefresh( t ) {
	setTimeout("location.reload(true);", t);
}
//   -->
</script>
</head>
<body onload="JavaScript:AutoRefresh(5000);">
<p>This page will refresh every 5 seconds.</p>
</body>
</html>

Here setTimeout() is a built-in JavaScript function which can be used to execute another function after a given time interval.

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements