Search code examples
javascriptjspinternet-explorer-7firefox3.5

At IE7, action "javascript:history.back()" in JSP jump back to main page, not previous viewed page


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>

Solution

  • I prefer to use

    history.go(-1);
    

    instead of

    history.back();