Computer >> Computer tutorials >  >> Programming >> Javascript

How to use JavaScript to redirect a webpage after 5 seconds?


To redirect a webpage after 5 seconds, use the setInterval() method to set the time interval. Add the webpage in window.location.href object.

Example

You can try to run the following code to learn how to redirect a webpage after 5 seconds −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         setTimeout(function(){
            window.location.href = 'https://www.tutorialspoint.com/javascript/';
         }, 5000);
      </script>
      <p>Web page redirects after 5 seconds.</p>
   </body>
</html>