Use disable the browser's Back button with js code

This uses jquery, jquery first introduced

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
function disableBack() {
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            window.history.pushState('forward', null, '');
            window.history.forward(1);
        });
    }
    window.history.pushState('forward', null, '');
    window.history.forward(1);
}

You can call the above function when the page is initialized.

Guess you like

Origin www.cnblogs.com/xl5230/p/11572344.html