
The redirecting feature in the JavaScript language is very useful when a web developer changes to a
new domain name. Of course, the frequent visitors of the site won't know that you have moved to a different domain unless they pay a visit to the web site. Now, to save some time, you could just redirect them to your new domain once they access your web site.
Web pages that have moved to different locations place a redirect page at their old location to transfer their visitors to their new site. That's not the only instance where redirects are used. Sometimes, it is also used to redirect visitors to a download site or when web servers mirror another site.
The page that will be loaded into the browser is set on the window location property of the JavaScript code. When you set a URL on this property, the web page will change into the location you have specified. A
time delay takes place before the old page is redirected to the location you have placed in your code. The implementation of time delay in your JavaScript code is useful to refresh the page every specified moment, for download sites that want to have a few seconds or before download begins, and to show a message to the visitors before the URL is changed.
Here is a sample code if you wish your visitors to be moved to the web site you have specified:
<! - Code Sample - !>
<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
window.location = "http://www.javascript-programming.com"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
<h2 >You will now be redirected</h2>
<p>You can put additional messages here</p>
</body>
</html>
<! - End Sample - !>