By 18/02/2014 1 Comments

How To Redirecting Webpage with Timer using Javascript

What is webpage redirect ?

  • Navigate from one website to another website is called redirect
  • We can also navigate from one site to another  using timer function

setTimeout() function

  • It is a javascript timer function which automatically executes after specified the given number of milliseconds
  • You can executes this function only ones
  • This function except given time in milliseconds. 1 second = 1000 milliseconds

Using  javascript it is very easy to redirecting a webpage to another url with help of  setTimeout function.

Javascript Code Snippet

<script type="text/javascript">

        var count = 6; // specified total number for countdown

        var redirect = ""; // assign an url to a variable

        function countDown() { // declare function

            var timer = document.getElementById("timer"); // get an html element by id timer and assign it into timer variable

            if (count > 0) { // check condition if count variable is greater then 0 return true

                count--; // every time an one digit will be minus from count

                timer.innerHTML = "This page will redirect in " + count + " seconds."; // assign string text into a html element for display

                setTimeout("countDown()", 1000); // setTimeout() function pass 2 parameters first is function (which will be called after 1 second according to second parameter) and second is time in milliseconds(defines after how much time this function countDown() willbe called)

            } else {

                window.location.href = redirect;  // this line opens a new URL and point out the location of that URL which specifies in redirect variable




HTML Code Snippet


<span id="timer"> <!-- display count down numbers here --->

<script type="text/javascript">countDown();</script> <!-- call above javascript function ---> 



Posted in: HTML, JavaScript

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .