【问题标题】:How to expire page on back button click?如何在后退按钮单击时使页面过期?
【发布时间】:2014-08-14 14:56:43
【问题描述】:

我在 jsp 页面中添加了以下元标记

<html>
<head>
<title>xyz</title>
<link type='text/css' rel="stylesheet" href="sdsds/sdsd"/>
<meta content="max-age=0" http-equiv="cache-control">
<meta content="no-store" http-equiv="cache-control">
<meta content="-1" http-equiv="expires">
<meta content="Tue, 01 Jan 1980 1:00:00 GMT" http-equiv="expires">
<meta content="no-cache" http-equiv="pragma">
</head>
<body><h1>jsdsdsds</h1>
<a href="abc">click me</a>
</body>
</html>

点击链接“点击我”导航后,我打开了一个新页面。当我单击后退按钮时,它正在工作..我希望页面过期.. 注意:在两个 jsp 页面中,我都添加了相同的元标记。 我尝试添加这个

<%@ page import="java.lang.*" %>
<%
// Set to expire far in the past.
response.setHeader("Expires", "Sat, 6 May 1971 12:00:00 GMT");
// Set standard HTTP/1.1 no-cache headers.
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>

在 HTML 上方和 Head 内部..我仍然可以看到后页。, 在 Mozilla firefox 10.0 和 IE8 中测试 有什么建议吗?

【问题讨论】:

    标签: html internet-explorer jsp firefox tomcat


    【解决方案1】:

    试试这个

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
       <html xmlns="http://www.w3.org/1999/xhtml" >
      <title>Untitled Page</title>
      <script type = "text/javascript" >
      function changeHashOnLoad() {
     window.location.href += "#";
     setTimeout("changeHashAgain()", "50"); 
     }
    
    function changeHashAgain() {
    window.location.href += "1";
    }
    
    var storedHash = window.location.hash;
     window.setInterval(function () {
     if (window.location.hash != storedHash) {
         window.location.hash = storedHash;
    }
    }, 50);
    
    
    </script>
     </head>
     <body onload="changeHashOnLoad(); ">
      Try to hit back!
     </body>
     </html>`
    

    【讨论】:

    • 欢迎来到 Stack Overflow!您是否会考虑添加一些叙述来解释为什么此代码有效,以及是什么使它成为问题的答案?
    【解决方案2】:

    只要不涉及会话,您就不能在浏览器的后退按钮上使页面过期。它用于对许多用户进行的页面的后退浏览,因此这取决于您希望用户如何浏览您的网站。您实际上需要处理浏览器的后退按钮。有几种方法可以做到这一点。 突出的是在 javascript 中使用此代码:`

    window.history.forward();
    

    ` 但它会将您的返回请求转发到历史记录中的当前页面 对我有用的是:

    <script type="text/javascript">
    function noBack(){
                location.replace(logouturl);
                window.location="logouturl";
    }
    

    HTML

    <input type="button" value="SignOut" onclick="noBack()" align="middle">
    

    【讨论】:

    • 我创建了一个会话,然后在我的控制器中编写了以下代码。但它仍然不会使页面过期。 response.setHeader("Cache-Control", "no-cache, no-store"); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "0"); response.setDateHeader("Expires", -1);你能帮忙吗?
    【解决方案3】:

    试试这个

     <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
     <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
     <META HTTP-EQUIV="EXPIRES" CONTENT="0">
    

    Check this link可能对你有帮助……

    【讨论】:

      猜你喜欢
      • 2014-01-20
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多