Disable Back Button in Browser using jquery?

后端 未结 8 672
慢半拍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:24

    Use following code as it is:

    window.onload = function () {
        if (typeof history.pushState === "function") {
            history.pushState("jibberish", null, null);
            window.onpopstate = function () {
                history.pushState('newjibberish', null, null);           
            };
        }
        else {
            var ignoreHashChange = true;
            window.onhashchange = function () {
                if (!ignoreHashChange) {
                    ignoreHashChange = true;
                    window.location.hash = Math.random();                
                }
                else {
                    ignoreHashChange = false;   
                }
            };
        }
    };
    

提交回复
热议问题