简体   繁体   中英

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>

I prefer to use

history.go(-1);

instead of

history.back();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM