Disable Back Button in Browser using jquery?

后端 未结 8 655
慢半拍i
慢半拍i 2020-12-03 05:55

I would like to Disable Back button when user click on logoff for this i delete only cookies of that user not session in my application. And want to disable Back button

相关标签:
8条回答
  • 2020-12-03 06:31
    This is another technique to disable the back functionality in any webpage. We can disable the back navigation by adding following code in the webpage. Now the catch here is that you have to add this code in all the pages where you want to avoid user to get back from previous page. For example user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1. In this case all following code in page1.

    CODE:

    <HTML>
        <HEAD>
            <SCRIPT type="text/javascript">    
                 window.history.forward();
                 function noBack() { 
                      window.history.forward(); 
                 }
            </SCRIPT>
        </HEAD>
        <BODY onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
        </BODY>
    </HTML>
    
    0 讨论(0)
  • 2020-12-03 06:32
    var path = 'Test.aspx'; //write here name of your page 
    history.pushState(null, null, path + window.location.search);
    window.addEventListener('popstate', function (event) {
        history.pushState(null, null, path + window.location.search);
    });
    

    This works across all browsers(except < IE10) even if urls have query strings appended.

    For this you don't even need jquery.

    have a look here to apply this for your page.

    0 讨论(0)
提交回复
热议问题