views:

94

answers:

3

Below are the code pieces in one jsp page, the function is to jump back to previous page, it works on Firefox 3.5, but does not work on IE7, at IE7, it will jump back to main index page. how to enhance it to support IE7/Firefox at the same time?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
<link rel='stylesheet' href="/css/main.css">
</head>
<body>

<div id="id1">

    <h2 class="centered">title</h2>

    <html:errors/>

    <p class="centered">
        <form action="javascript:history.back()">
            <input type="submit" value='back'>
        </form>
    </p>
</div>

</body>
</html>
+1  A: 

I'm betting you're using an AJAX application. The problem is the IE7 does not update the history stack on hash changes or any AJAX action for that matter. There are ways around it though, I'd personally recommend http://www.mikage.to/jquery/jquery_history.html

Robert
A: 

I prefer to use

history.go(-1);

instead of

history.back();
Garis Suero
I changed it from history.back() to history.go(-1), it works on both IE7 and FF3.5.
Emre He
Nice... so this is the answer you were looking for...
Garis Suero
+1  A: 

Don't use JavaScript for this. Just let JSP/Servlet remember the previous page and put its URL in <form action> instead. You can grab the request URL by HttpServletRequest#getRequestURL().

Or, better, display the errors in the same page as the original form. This way you don't need to bother the enduser to remember all the errors before taking the extra action to go back to a page without error messages. Yes, this is bad user experience.

BalusC