disable back button in browser using javascript – To disable web browsers’ back button, try to run the following code.
stop the browser back button Example
window.onbeforeunload = function() { return "sorry, Your some work will be lost - really sorry."; };
Example 1:
<script type="text/javascript">
function disableBack() { window.history.forward(); }
setTimeout("disableBack()", 0);
window.onunload = function () { null };
</script>
Example : 2
window.history.pushState(null, null, window.location.href);
window.onpopstate = function () {
window.history.go(1);
};
Example : 3
<script type = "text/javascript" >
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };
</script>
index Page(index.html)
<script type="text/javascript">
function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };
</script>
<h3>index</h3>
<hr />
<a href="dashboard.html">Redirect to dashboard</a>
Dashboard Page (dashboard.html)
<h3>Dashboard</h3>
<hr />
<a href="index.htm">Redirect to index</a>
I hope you get an idea about disable back button in browser using javascript.