JavaScript

How to redirect to another page after 5 seconds in Javascript

In this tutorial, we are going to see how to redirect to another page after 5 seconds in Javascript

The following JavaScript example, which is between the <HEAD> and </HEAD> tags, opens the website “https://stackhowto.com” in the same browser window.

<script language="javascript" type="text/javascript">
     window.location="https://stackhowto.com";
</script>

The window.setTimeout() method triggers a timer and performs an action after a delay expressed in milliseconds. So the following JavaScript example opens the website “https://stackhowto.com” in the same browser window after displaying the current page for 5 seconds (5000 ms).

<script language="javascript" type="text/javascript">
  window.setTimeout('window.location="https://stackhowto.com"; ',5000);
</script>
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *