Wednesday, 24 July 2013

Disable browser back button when session has expired



Simply add following jquery code in your jsp file.

<script type="text/javascript">
$(function(){
     window.history.forward();
     function noBack() {window.history.forward(); }
     window.onpageshow=function(evt){if(evt.persisted)noBack();};
     window.onunload=function(){void(0);};
});
</script>


Alternative you can add following scriptlet in jsp file also.

<%
response.setHeader("Pragma", "no-cache");  
response.setHeader("Expires", "0");  
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");  
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
%>


No comments:

Post a Comment