Javascript Redirection

Jeff Andersen (Other / Beginner)

Javascript is a great way to redirect a user when you need to, there are several options to choose from aswell as it works with every

browser that has javascript enabled. The script takes control of the window and changes it location using window.location. For a basic redirect all you need to include is this:
<script type="text/javascript">
<!--
window.location = "http://URLHERE"
//-->
</script>
This is great, but it is automatic and you might want to tell a user they will be changing locations, or let a user know why they are changing locations. This is done through a time delay function within javascript. This method can also be used to refresh a page at a specified interval without the user having to do anything.
<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
window.location = "http://URLHERE"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 3500)">
<p>Redirection warning text!</p>
</body>
</html>
What this is doing is tell the browser that when it loads, pause for the specified ammount of time (in this case 3.5 seconds, stated in milliseconds) then to carry out the operation.


© Copyright 2006 - All Rights Reserved - SiteGuts is a part of the Enthonia Content Network