4-Nov-05 (Created: 4-Nov-05) | More in 'Howto-Advanced'

How does aspire implement client side redirect

Rationale

During the early days of servlets I have used a trick to accomplish client side redirect after an update took place. This client side redirect will erase the update url from the browsers memory making the "back" and "refresh" buttons safe to the user.

Implications

Some times this gets me into hot water. The target url may have special characters making the javascript fail. Atleast by looking at the code below you know what the issues are if that happens and hopefully correct them accrodingly.

Sample code


<html><head>
<script>
function redirectToTarget()
{
   targetUrl = "some-url-string";
   if (targetUrl == "")
   {
      alert("No target url specified");
      return;
   }
   else
   {
      location.replace(targetUrl);
   }
}
</script>
</head>
<body onLoad=redirectToTarget()>
</body>
</html>