Home >Web Front-end >JS Tutorial >How to refresh a web page using JavaScript_Basic knowledge
You can use the JavaScript location.reload method to refresh the web page. This code can be automatically called in an event when the user clicks a link.
If you want to refresh the web page using mouse clicks, you can use the following code:
<a href="javascript:location.reload(true)">Refresh Page</a>
To know a better way, you can refresh the page
Auto refresh:
You can also use JavaScript to automatically refresh the page after a given time period. The following is an example of refreshing this page every 5 seconds. This time can be changed 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>
The setTimeout() here is a built-in JavaScript function that can be used to execute another function after a given time interval.