Sunday, February 3, 2008

Meta refresh redirect - Don't use it

Meta refresh breaks the Back button - http://www.w3.org/QA/Tips/reback

Sample code for Meta refresh redirect:

<html>

<head>
<title> Redirecting to correct page </title>
<META http-equiv="refresh" content="5;URL=http://jhpatel.blogspot.com/"> </head>

<body>
<center>
You will be redirected automatically in 5 seconds. Please bookmark the page at
<a href="http://jhpatel.blogspot.com/" > http://jhpatel.blogspot.com/</a>
</center>
</body>

</html>


Better way :

HTTP 301 Redirect - Permanent redirect (In JSP)

response.setStatus(301);

response.setHeader("Location", "http://www.jhpatel.blogspot.com/");

response.setHeader("Connection", "close");

Saturday, February 2, 2008

Implement browser back button in your page

Add following line in your html page:

<input value="back" onclick="history.go(-1)" type="button">

If you want user to always go back one page, you can use history.back() Instead of history.go(-1).