Question

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>
Was it helpful?

Solution

I prefer to use

history.go(-1);

instead of

history.back();

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top