Home  >  Article  >  Web Front-end  >  How to refresh a web page using JavaScript_Basic knowledge

How to refresh a web page using JavaScript_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 15:56:391518browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn