4

I know you can do javascript:history.go(-2) to make the user go back 2 pages, however I was curious if it were possible in any way to actually make pressing the back button on the browser go back 2 as well.

I didn't think something like this was possible until I read: Disable browser's back button
So maybe it is?

Community
  • 1
  • 1
dukevin
  • 22,384
  • 36
  • 82
  • 111
  • no its not possible unless you write your own browser and implement back button this way or perhaps introduce a new button back2X. – Ehtesham Sep 06 '11 at 12:49

1 Answers1

3

If you read that older post more carefully, you'll see that what the answers are suggesting is not technically disabling the browser's back button. It's clearing the cache so that there's nothing to go back to. It's a hack to achieve a specific effect.

Because I can't resist making stupid comparisons...

This difference between disabling the back button and setting the cache so that there's nothing to go back to is like asking "Can we disable channel 8 on the television." The answers are not about how to disable the television's ability to display channel 8. They're more like talking about how to block the airwaves or blowing up the TV station to achieve the same effect.

The point is, you can't control the client's browser in the way you're asking.

David
  • 72,686
  • 18
  • 132
  • 173
  • Well, would it be possible to only clear the last entry in the cache so that pressing Back on the browser has the effect as going back 2? – dukevin Sep 06 '11 at 12:51
  • No, because the browser will still go back tot he previous page and give a "this page needs to be refreshed" message. – David Sep 06 '11 at 12:54
  • In the other posts, the browser can still go back to the previous page, but the user will see an error, or will not be able to re-view the page without re-submitting hte form data that was used to create the content on the page. – David Sep 06 '11 at 12:55
  • My knowledge on Js is limited but perhaps you can trigger the history.go(-2) with something like "window.lostfocus()" to sort of emulate this if the mouse cursor leaves the window and onto the browser UI (maybe the backbutton). Is it possible (probably not) with JS to see if the mouse is hovering over the backbutton? – dukevin Sep 06 '11 at 13:03
  • Unfortunately, lostFocus would be triggered when the user switched to check email or minimized the browser, etc. You could possibly use the event that occurs when the user tries to leave the page as described here: http://mistonline.in/wp/alert-a-message-before-leaving-a-web-page-using-javascript/ but consider that this would happen even if they tried to navigate to another site completely. It's bad form and would get annoying pretty fast. Also, you can't capture hovering over browser items like browser buttons - just HTML elements in the viewable browser area. – David Sep 06 '11 at 13:12
  • I do like how you're thinking of alternatives. You may just come up with something to prove me wrong. If you do, please update this and let me know! – David Sep 06 '11 at 13:14