Disable browser “Back” button

2019-01-29 12:53发布

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 any way to disable the back button in the toolbar?

thanks

标签: html button
3条回答
叼着烟拽天下
2楼-- · 2019-01-29 13:06

Write this code between script tags

    history.pushState(null, null, location.href);
    window.onpopstate = function () {
        history.go(1);
    };
查看更多
beautiful°
3楼-- · 2019-01-29 13:13

There's no way to disable the Back-button using regular HTML as you specify.

查看更多
来,给爷笑一个
4楼-- · 2019-01-29 13:26

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

查看更多
登录 后发表回答