Disable browser “Back” button

前端 未结 3 1476
别跟我提以往
别跟我提以往 2020-12-22 12:52

how can I disable the browser\'s \"Back\" button in a HTML page? I do not want to create JavaScript window to avoid showing any toolbar,etc. In regular HTML page, is there

相关标签:
3条回答
  • 2020-12-22 13:15

    You can't technically disable it, and moreover you shouldn't. Disabling the back button of a browser would fundamentally change the browsing experience for a user which isn't your place to do.

    If going back in the browser creates problems for your application then you should restructure your workflow so it doesn't. An example of this is implementing the POST/REDIRECT/GET pattern.

    More Info: http://en.wikipedia.org/wiki/Post/Redirect/Get

    0 讨论(0)
  • There's no way to disable the Back-button using regular HTML as you specify.

    0 讨论(0)
  • 2020-12-22 13:35

    Write this code between script tags

        history.pushState(null, null, location.href);
        window.onpopstate = function () {
            history.go(1);
        };
    
    0 讨论(0)
提交回复
热议问题