Tuesday, May 10, 2011

How to disable back button of browser and not delete the history?

To disable back button of browser ... delete history
Put this javascript at the <head> tag
    <script type="text/javascript">
        function setFocus()
        {
            document.getElementById("contentPage").focus();
            var URL;
            var i;
            var QryStrValue;
            URL = window.location.href;
            i = URL.indexOf("?");
            QryStrValue = URL.substring(i + 1);
            if (QryStrValue != 'X')
            {
                window.location = URL + "?X";
            }
        }
     </Script>
Then call your function using onload event in <body> tag.
<body onload="setFocus()">
Here is the reference that I use:
http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/60682

No comments:

Post a Comment