How to expire page on back button click?

2019-01-26 00:52发布

I have added following meta tag in jsp page

<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>

After navigating by clicking link "click me" I am opening a new page. When I click back button it is working..I want the page to expire.. Note:In both jsp page I have added same meta tag. I tried adding this

<%@ 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
%>

both above HTML and inside Head..still I can see back page., Tested in mozilla firefox 10.0 and IE8 Any suggestion?

3条回答
We Are One
2楼-- · 2019-01-26 00:56

try this

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

Check this link it might be helpful to you...

查看更多
Lonely孤独者°
3楼-- · 2019-01-26 01:04

Try this

 <!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>`
查看更多
趁早两清
4楼-- · 2019-01-26 01:12

You cannot expire a page on back button of browser as long as sessions aren't involved.Its there for back browsing of pages which many users do, so it depends on how you want user to browse your site. You actually need to handle the back button of browser. There are few ways to do it. Prominent one is using this code in javascript:`

window.history.forward();

` but it will forward your back request to current page in history The one that worked for me is:

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

HTML

<input type="button" value="SignOut" onclick="noBack()" align="middle">
查看更多
登录 后发表回答