Another example is changing, say, details of a user account. When the page is saved, a common task would be to submit the form to a servlet or JSP, then redirect back to the page. We don't want the user to hit back and reach an out of date page.
This can be done via javascript using location.replace and in Mozilla/Firefox with location.href. These change the URL in address bar and load the page specified, but without creating history. Changing location alone creates history. In the example below, ${navigateTo} stores the location to forward the user to.
if (document.images) // check for IE
location.replace('&{navigateTo}');
else // Mozilla, Firefox
location.href='&{navigateTo}';
And to give time for the user to see the output before forwarding them:
if (document.images)
window.setTimeout("location.replace('&{navigateTo}')","5000");
else
window.setTimeout("location.href='&{navigateTo}"',"5000");
No comments:
Post a Comment