Javascript Redirect

You may need to use Javascript Redirect in following situations

  • You have a new and updated content and you want to redirect your users there.
  • You want to introduce some time delay to grab user's attention and then redirect him/her to a specific webpage.
  • You have got yourself a new domain name.

Well you can easily do so with javascript. If you want to perform a simple redirect i.e. upon landing on your webpage the user should be redirected to some other page use the code snippet given below -

<script type="text/javascript">

<!--

window.location = "http://www.botskool.com/";

//-->

</script>

If you want to introduce a time delayed redirect then use the following script -

<html>

<head>

<title>Sample Webpage to be redirected</title>

<script type="text/javascript">

<!--

function redirect(){

window.location = "http://www.botskool.com";

}

//-->

</script>

</head>

<body onLoad="setTimeout('redirect()', 5000)">

<h2>Redirecting in 5 seconds!</h2>

</body>

</html>

Notice the setTimeout() function it takes two arguments - first one is a function name and the second one is time delay in milliseconds after which it should execute the function mentioned in first argument. Here in this script setTimeout() waits for 5000 milliseconds i.e. 5 seconds before executing redirect() function which in turn redirects the page.