Sunday, 22 August 2021

Reload/refresh web page after specific interval of time using jQuery

 Hi guys, in this post we will see how to reload web page after specific interval of time using jQuery.

Let's see it practically.  In our web application, we may have requirement of reloading web page after some interval of time.

Please follow below steps:-

1)Open your editor or any editor.

2)Add <html>,<head>,<script> and <body> tag.

3) Add jQuery CDN link in head section for jQuery reference file.

4) Add following jquery code in script section:-

    <script type="text/javascript">

    $(document).ready(function(){

setInterval(function()

      

     location.reload(); 

      }, 3000);

});

</script>

In above code, we have added document ready function. In document ready function we have used setInterval() method which calls function after some specific interval of time. In our case 3000 millisecond means 3 second. Using this code ,function code will be executed after each 3 seconds and page will be refreshed. We are using  location.reload(); to refresh web page.

Full Code:-

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function(){

setInterval(function()

  { 

     location.reload(); 

  }, 3000);

});

</script>

</head>

<body></body>

</html>


No comments:

Post a Comment