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.

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

Example

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>
raja
Published on 01-Feb-2018 05:20:17
Advertisements