How to disable Browser Back button in asp.net application
Hi, Recently i got a requirement, to disable browser back button through out application. I tried with different ways like
function disableBackButton() { window.history.forward() }
disableBackButton();
window.onload = disableBackButton;
window.onpageshow = function(evt) { if (evt.persisted) disableBackButton() }
window.onunload = function() { void (0) }
I put the above code in master page, but in some scenario this is not working fine, and more over when i click browser back button page is loading.
After then I tried with following code. Put the follwoing code in Master page Header section.
<script type="text/javascript">
function changeHashOnLoad() {
window.location.href += "#";
setTimeout("changeHashAgain()", "50");
}
function changeHashAgain() {
window.location.href += "1";
}
var storedHash = window.location.hash;
window.setInterval(function() {
if (window.location.hash != storedHash)
{ window.location.hash = storedHash; } }, 50);
</script>
<body onload ="changeHashOnLoad();">
Using the above code the browser back button will not work in all browsers and page loading also avoided.. I hope itwill work fine.
With Regards
Phanikumar Kowta