Grant Communications LLC provides Internet Marketing, which is core to our MA and NH client's success in business development.
Internet Marketing • Website Design & Development
Call for internet marketing solutions.
  • Internet Marketing
  • Web Development
  • Corporate Identity

 

 

JavaScript Redirect

You're moving to a new domain name. You have a time-delay in place on your download site. You have a list of external web servers that are helping to mirror your site. What will help you deal and/or take advantage of these situations? Javascript redirects will.

When a web page is moved will most probably would like to place a "redirect" page at the old location that informs the visitor of the change and then after a timed delay, will forward the visitor to the new location. With the javascript redirection, you can do just this.

Javascript Window.Location

The control over what page is loaded into the browser rests in the javascript propety window.location, by setting this equal to a new URL you will in turn change from the current web page to the one that is specified. If you wanted to redirect all your visitors to www.google.com when they arrived at your site you would just need the script below:

HTML & Javscript Code:

<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>

Javascript Time Delay

Implementing a timed delay in javascript is useful for the following situations:

  • Showing an "Update your bookmark" page when you have to change URLs or page locations
  • For download sites that wish to have a few second delay before the page loads and when the download starts
  • To refresh a web page every specified amount of seconds

The code for this timed delay is slightly involved and is beyond the scope of this tutorial. However, we have tested it and it seems to function properly.

HTML & Javscript Code:

<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
document.location = "../javascriptredirect.php"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 5000)">
<h2 >Prepare to be redirected!</h2>
<p>This page is a time delay redirect, please update your bookmarks to our new location!</p>

</body>
</html>

View Page:

The most important part of getting the delay to work is being sure to use the javascript function setTimeout. We want the delayer() function be used after 5 seconds or 5000 miliseconds, so we pass the setTimeout() two arguments.

  • 'delayer()' - The function we want setTimeout() to execute after the specified delay.
  • 5000 - the number of milisecods we want setTimeout() to wait before executing our function. 1000 miliseconds = 1 second.

Web Page Redirection

Do use javascript for redirections when you change your website's URL or move a file to a new location. Don't use redirections when they could easily be replaced with a normal HTML hyperlink.

 

MA web design logo

 

     

 

 

Contact Us for Internet Marketing Today!