Home > Web Front-end > JS Tutorial > body text

How to refresh a web page using JavaScript_Basic knowledge

WBOY
Release: 2016-05-16 15:56:39
Original
1534 people have browsed it

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>

Copy after login

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>

Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template