A nice little Javascript redirect

Posted: July 12th, 2009 | Author: admin | Filed under: Websites | Tags: , , | No Comments »

I customized a 404 page today. Just with some text to let the user know the page wasn’t there with a few links to existing content on the domain. Then, using the script below it redirects the visitor to my homepage in 2 seconds. A nice way to capture your 404 traffic I thought.

This example is setup to redirect to another page in 2 seconds. When a page contains this JavaScript, it will be redirected to another page that you specify in the “window.location=“. You can change the number of refresh seconds by changing the “move()’,2000 to the number of seconds you’d like.

Example:

1000 = 1 second
3000 = 3 seconds
Place this code between the <head> and </head> tags

<script language=”JavaScript”>
var time = null
function move() {
window.location = ‘http://www.yourdomain.com’
}
//–>
</script>

Place this code in your <body> tag

<body onload=”timer=setTimeout(’move()’,2000)”>