12-Jul-03 (Created: 12-Jul-03) | More in 'CS-JavaScript'

How to redirect to a different page on reload?

The obvious way

Redirecting to a different page on reload is a bit tricky. The first choice seem to suggest to do the following on reload

document.location=(your redirect url)

What then is the problem?

The above statement will transfer the browser to the new specified url. The problem comes when the user hits the "back" button. The page will redirect you again to the same page that you are looking at. To solve this you need to tell the browser to remove the back link from its history. You do this by using the "replace" function on the "location" reference.

A workable solution follows

<html>
<head>
<script>
	function redirectTo()
	{
		location.replace("http://216.187.231.34/akc");
	}
</script>
</head>

<body onload="redirectTo()">
</body>
</html>