Thursday, 19 September 2013

Disable Back button of browser using JavaScript.

Add this script in your HTML code.

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

</script>

Eg:

<html>

    <head>
    <title>Disable Back button</title>
    </head>

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

<body>
     Sample Page
</body>
</html>