This article mainly introduces JavaScript to disable browser back button implementation, the need for friends can refer to the following
1, code as follows: <script language= "JavaScript" > javascript:window.history.forward (1); </ script> Use JS to generate a "forward" action to counteract the back function, this method should be the most concise, and do not need to consider the user point two or more times "back" situation, the disadvantage is that when the client has disabled JavaScript after the failure. 2, code is as follows: <a href= "logout.do" onclick= "Javascript:location.replace (THIS.HREF); Event.returnvalue=false; "> Logout (back Disabled) </A> location.replace from one page to another page." The rationale for this approach 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 the way many people are looking for, but it's still not the best way to do it in any situation. The disadvantage of this approach is that simply using Response.Redirect will no longer work, because every time a user moves from one page to another, we must clear the Location.history with client code. Also note that this method clears the last access history, not all the access records. 3, when the keyboard hit the Back button (Backspace) after the 1, prohibit the browser automatically back to the 2, but does not affect the password, single-line text, multi-line text input boxes, such as rollback operation Code as follows: <script type= "Text/javascript" > //Handling keyboard events prevent back key (Backspace) passwords or single, multiline text boxes except function Banbackspace (e) { var ev = e | | window.event;//get event object var obj = Ev.target | | ev.srcelement;//getEvent source var t = Obj.type | | Obj.getattribute (' type '); Get event Source Type //Get event type as judgment condition var vreadonly = Obj.getattribute (' readonly '); var venabled = Obj.getattribute (' enabled '); //handling Null value condition Vreadonly = (vreadonly = null)? false:vreadonly; venabled = (venabled = null)? true:venabled; //When the BACKSPACE key is hit, the BACKSPACE key fails when the event source type is a password or a single line, multiline text, //And the ReadOnly property is True or the Enabled property is False. var flag1= (Ev.keycode = = 8 && (t== "Password" | | t== "TEXT" | | t== "TEXTAREA") && (vreadonly==tr UE | | Venabled!=true)?true:false; //When knocking the BACKSPACE key, the event source type is not a password or single line, multi-line text, the BACKSPACE key invalidation var flag2= (Ev.keycode = 8 && t!= "password" && t!= "text" && t!= "textarea") ?true:false; //judgment I F (flag2) { return false; } if (FLAG1) { -return false; } } //No Back key function in Firefo X, opera document.onkeypress=banbackspace; //No back key acts on IE, chrome document.onkeydown=banbackspace; </script> The above methods are for the "back" button to react, The client browser needs to open the JavaScript code. 4, prohibit caching code 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 scripting to force browsers to re-enter the server download page without reading from the cache, combining struts The <logic> label implementation redirects in the JSP page. above various methods have certain limitations 5, code as follows: <script language= "JavaScript" > function logout () { Window.close (true); window.open ("logout.do"); } </ script> <button onclick= "logout ()" >Logout</button> This method is more lazy, turn off the browser and reopen it, After my test on the visual almost not feel the delay, while also ensuring that the back button is not available (the new Window browser Back button is gray), it seems to be a good way, but the disadvantages are more obvious: first of all, closed and re-opened the browser window size may be different, The user can clearly see this process and affect the operation to some extent. Second, ditto, this is a JavaScript method. &NBSP;