How to Refresh Web Page using javaScript

AuthorSumit Dey Sarkar

Pubish Date31 Aug 2022

categoryJavaScript

In this tutorial we will learn how to refresh web page using javaScript.

We can use this when we need to refresh web page after every 5 second , 10second , 15 second , 20second , 25 second , 30 second etc.

Here we will see two examples -

1) using setTimeout

2) Using setInterval

let's see examples one by one

1) How to refresh web page using javaScript setTimeout

<!DOCTYPE html>
<html>
<head>
	<title>How to refresh web page after 10 second using javaScript setTimeout</title>
</head>
<body>

<h2>How to refresh web page after 10 second using javaScript setTimeout</h2>

<script type="text/javascript">
   setTimeout(function(){
       location.reload();
   },10000);
</script>

</body>
</html>

 

2) How to refresh web page using javaScript setInterval

<!DOCTYPE html>
<html>
<head>
	<title>How to refresh web page after 10 second using javaScript setInterval</title>
</head>
<body>

<h2>How to refresh web page after 10 second using javaScript setInterval</h2>

<script type="text/javascript">
function refreshWebPage()
    {
        window.location = window.location.href;
    }
    setInterval('refreshWebPage()', 10000);
</script>

</body>
</html>
Comments 0

Leave a comment