Disable browser's back button

后端 未结 20 1338
猫巷女王i
猫巷女王i 2020-11-22 04:27

How to disable browser\'s BACK Button (across browsers)?

20条回答
  •  有刺的猬
    2020-11-22 05:14

    Others have taken the approach to say "don't do this" but that doesn't really answer the poster's question. Let's just assume that everyone knows this is a bad idea, but we are curious about how it's done anyway...

    You cannot disable the back button on a user's browser, but you can make it so that your application breaks (displays an error message, requiring the user to start over) if the user goes back.

    One approach I have seen for doing this is to pass a token on every URL within the application, and within every form. The token is regenerated on every page, and once the user loads a new page any tokens from previous pages are invalidated.

    When the user loads a page, the page will only show if the correct token (which was given to all links/forms on the previous page) was passed to it.

    The online banking application my bank provides is like this. If you use the back button at all, no more links will work and no more page reloads can be made - instead you see a notice telling you that you cannot go back, and you have to start over.

提交回复
热议问题