Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using this client side code to disable browser back button. The function "changeHasgOnLoad" is called in body tag's onload
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);

Its working fine but when i open it in IE its preventing page from scrolling. but when i refresh the page then it works well. Please help me if anyone can know its reason.
Posted

1 solution

You shouldn't disable the back-button in the first place. It's the property and right of the user. Have you never experienced those freakingly annoying websites that disallow you to go back and wanted to punch the responsible person? Instead you should design your application in such a way that it is able to deal with back-navigation. It's not only nicer to the user but also the safer option for you. Not only you won't have to deal with these kind of quirks you are experiencing with IE here but also you don't risk your application misbehaving in case someone is able to navigate back despite your counter measures.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900