Tuesday 6 August 2013

Disable the back button on Browser

Disable the back button on Browser:

Solution 1:

Step 1: Body onload write a function and call the below code.

<body onLoad="backButtonOverride()" onpageshow="if (event.persisted) backButtonOverride();" onunload="">

// write your html code.............

</body>

<script>
function backButtonOverride() {

window.history.forward();
setTimeout("backButtonOverride()", 1);

}
</script>

Here, window.history.go(1) same as window.history.forward(); 
          setTimeout calls the backButtonOverride() on every second. 1000 = 1 sec

Step 2: Add below code in servlet or any interceptor

   if(response!=null){
response.setHeader("Cache-control","private, no-cache, no-store");
response.setHeader("Pragma","no-cache");
response.setHeader("Expires","0");
response.setDateHeader("Expires",-1);
}  
        

Solution 2:

Some times you will get Expired Page Problem on click of Back button. 
For this you have send the method ="get" instead of "Post". 

For security reasons we have to write the encryption and decryption code for user sensitive data.
Please check the below link for reference program for encryption and decryption: 
http://www.roseindia.net/answers/viewqa/JSP-Servlet/25684-Password-encryption-and-decryption.html

Solution 3:

Using Struts 2 Token Interceptor concept we can solve this issue.

No comments:

Post a Comment

SpringBoot

SpringBoot SpringBoot Application :  Pros & Cons :  SpringBoot Application creation using spring.io :  SpringBoot Application Annotation...