Wednesday, 24 December 2014

Disable back button

Sometimes we want that our page should not go back to previous page. Or back button should be disabled after log out. This can be done by using following JavaScript.
Write this code on the page on which you want to disable back button.

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

Summary
In this article I try to expose how to disable back button. I hope after reading this article you will be able to use this trick in your code. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.

No comments:

Post a Comment