feedback

How to make a javascript redirection script

If you need to redirect visitors from one page to another or if you changed the domain you need a redirection script. Redirection can be done in many different ways but i will show you the simplest way, that is using a java script. Java script only needs to be supported by browsers and every modern browser supports it. So java script is the best way for doing redirection.

The main part of redirection is to use window.location=”http://something.com”. Put this in one function and it will look like this:

function redirect(){
window.location = "http://www.skepo.info"
}

But we don’t want to redirect visitor just like that. We will set delay of let say 5 seconds and show visitor message that he will be redirected to other location. For that there is a function setTimeout(), it needs 2 parameters: first is what to do when the time elapses and second how much time does it need to wait in milliseconds. Let’s say we want to load redirect function after 5000 milliseconds (5 seconds):

setTimeout(redirect(),5000)

Now we will put this in the body tag, add it as parameter to onLoad.
And the whole thing looks like this:

<html>
<head>
<title>Redirecting</title>
<script type="text/javascript">
function redirect(){
window.location = "http://www.skepo.info"
}
</script>
</head>
<body onLoad="setTimeout('redirect()', 5000)">
<h2>Skepo is moved to a new domain!</h2>
You will be redirected to a new domain in 5 seconds. If you
don't want to wait click <a href="http://www.skepo.info">
here</a>
</body>
</html>

And that’s it!!

Digg icon Delicous icon Stumbleupon icon Reddit icon Twitter icon Facebook icon Technorati icon

Leave a Reply

You can use some HTML tags

Random Quote

quote openAlways code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.quote end
by Martin Golding

Tag cloud