I'll set the script at HEAD element and use onpageshow and onload event in the body element.
The Javascript put in Head element
<script type="text/javascript"> window.history.forward(); function noBack() { window.history.forward(); document.getElementById("Message").innerHTML = "You cannot Go Back"; } </script>
The Html/Aspx/Jsp page
: : Head element : <body onpageshow="if (event.persisted) noBack();" onload="noBack();" > : : body content <div id="Message" style="color:red;"> </div> : : </body> </html>
The Output
If the user click on the browser back button, the script will automatically redirect to the current page and give the message "You cannot go back" to user
Note : You can customize the script for example if you want to force logout user if user click on the back button, you can create one page "forceLogout.aspx" and then edit the script to redirect page to forceLogout.aspx . So everytime user click on the browser back button , user will redirect to forceLogout.aspx page.
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment