Prevent Use of the Back Button (in IE)

前端 未结 15 2019
囚心锁ツ
囚心锁ツ 2020-11-27 21:16

So the SMEs at my current place of employment want to try and disable the back button for certain pages. We have a page where the user makes some selections and submits the

15条回答
  •  醉话见心
    2020-11-27 21:52

    If you are starting a new web app from scratch, or you have enough time to rework your app, you can use JavaScript and AJAX to avoid the browser's history, back, and forward functions.

    • Open your app in a new window, either before or immediately after login.
    • If you wish, use window options to hide the nav bar (with the back and forward buttons).
    • Use AJAX for all server requests, without ever changing the window's location URL.
    • Use a simple web API to get data and perform actions, and render the app using JavaScript.
    • There will be only one URL in the window's history.
    • The back and forward buttons will do nothing.
    • The window can be closed automatically on logging out.
    • No information is leaked to the browser history, which can help with security.

    This technique answers the question, but it also contradicts best practice in several ways:

    • The back and forward buttons should behave as expected.
    • An app should not open new browser windows.
    • An app should still function without JavaScript.

    Please carefully consider your requirements and your users before using this technique.

提交回复
热议问题