Disable browser's back button

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

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

20条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 05:19

    I came up with a little hack that disables the back button using JavaScript. I checked it on chrome 10, firefox 3.6 and IE9:

    
    
    Untitled Page
    
    
    
    Try to hit the back button!
    
    
    

    What is it doing?

    From Comments:

    This script leverages the fact that browsers consider whatever comes after the "#" sign in the URL as part of the browsing history. What it does is this: When the page loads, "#1" is added to the URL. After 50ms the "1" is removed. When the user clicks "back", the browser changes the URL back to what it was before the "1" was removed, BUT - it's the same web page, so the browser doesn't need to reload the page. – Yossi Shasho

提交回复
热议问题