1.
The code copy is as follows:
<script language="JavaScript">
javascript:window.history.forward(1);
</script>
Using JS to generate a "forward" action to offset the back function, this method should be the simplest and does not need to consider the situation where the user points "back" twice or multiple times. The disadvantage is that when the user disables JavaScript It will expire afterwards.
2.
The code copy is as follows:
<A HREF="logout.do" onclick="javascript:location.replace(this.href); event.returnValue=false; ">
Logout (Back Disabled)
</A>
Use location.replace to go from one page to another. The principle of this method is to replace the current history with the URL of the new page, so that there is only one page in the browsing history and the back button will never become available. I think this may be exactly the approach many people are looking for, but this approach is still not the best way in any case. The disadvantage of this approach is that simply using Response.Redirect will no longer work, because every time the user goes from one page to another, we have to clear the location.history with client code. Also note that this method clears the last access history, not all access records.
3.
When the keyboard presses the Backspace key (Backspace)
1. Prohibit the browser from automatically backing
2. But it does not affect the fallback operation of password, single-line text, multi-line text input box, etc.
The code copy is as follows:
<script type="text/javascript">
//Except for backspace password or single or multi-line text boxes when handling keyboard events, except for backspace.
function banBackSpace(e){
var ev = e || window.event;//Get event object
var obj = ev.target || ev.srcElement;//Get the event source
var t = obj.type || obj.getAttribute('type');//Get the event source type
//Get the event type as a judgment condition
var vReadOnly = obj.getAttribute('readonly');
var vEnabled = obj.getAttribute('enabled');
// Handle null value situation
vReadOnly = (vReadOnly == null) ? false : vReadOnly;
vEnabled = (vEnabled == null) ? true : vEnabled;
//When the Backspace key is typing, the event source type is password or single-line or multi-line text.
// If the readonly property is true or the enabled property is false, the backspace key will be invalid
var flag1=(ev.keyCode == 8 && (t=="password" || t=="text" || t=="textarea")
&& (vReadOnly==true || vEnabled!=true))?true:false;
// When the Backspace key is typing, if the event source type is not a password or a single line or multiple lines of text, the backspace key will be invalid.
var flag2=(ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea")
?true:false;
//judge
if(flag2){
return false;
}
if(flag1){
return false;
}
}
//The back key is prohibited from acting on Firefox and Opera
document.onkeypress=banBackSpace;
//The back key is prohibited from acting on IE and Chrome
document.onkeydown=banBackSpace;
</script>
The above methods are all reacting to the "Back" button, and the client browser needs to open JavaScript code.
4. No caching
The code copy is as follows:
<%
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Cache-Control", "no-store");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
%>
This method uses server-side scripts to force the browser to revisit the server download page without reading from the cache, and combines the <logic> tag in the struts jsp page to achieve redirection.
All the above methods have certain limitations
5.
The code copy is as follows:
<script language="JavaScript">
function logout(){
window.close(true);
window.open("logout.do");
}
</script>
<button onClick="logout()">Logout</button>
This method is lazy. Turn off the browser and then reopen it. After my test, I almost couldn't visually feel the delay, and at the same time, the back button is not available (the back button of the browser in the new window is gray), it seems that it seems It's a good way, but its disadvantages are quite obvious:
First, the size of the closed and reopened browser windows may be different, and the user can clearly see this process and affect the operation to a certain extent.
Secondly, suppose above, this is a JavaScript method.