From: David Mark on
On Jul 17, 6:55 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote:
> On 2010-07-17 12:48 PM, David Mark wrote:
>
> > On Jul 17, 11:11 am, pebkac wrote:
> >> I've been getting complaints from users who hit backspace outside of a
> >> textbox by accident, and get taken "back" a page by their browser.
>
> > That's what browsers do.
>
> That is what IE did and what other browsers copied but that behavior can
> be configured by some browsers. For example, in Firefox, setting
> `browser.backspace_action` to -1 will stop that.
>
> http://kb.mozillazine.org/Browser.backspace_action#Possible_values_an...
>
> [...]
>
> It may be worth mentioning this to the user, so that the user can
> reconfigure his browser to avoid the undesirable user experience.
>

Yes, but the OP also seemed unhappy with navigation by other means
(e.g. the back button), which also caused the application to lose its
state.

>
>
>
>
>
>
> >> Is there a simple way to disable this using javascript? I've tried
> >> trapping the unload event, but this doesn't seem to fire in the case of
> >> the backspace/back action.
>
> >> Any ideas greatly appreciated :)
>
> > Don't disable built-in navigation under any circumstances.  If your
> > application works with fast history navigation (which is disabled by
> > using an unload listener), then the user can simply go forward and
> > return to the state they were in before they left.  Of course, some
> > browsers (e.g. IE) lack this feature (or at least implement it in a
> > way that destroys the DOM state), so if you want to solve this for all
> > users, you need to look into persisting the application state yourself
> > (e.g. with cookies or localStorage).
>
> There are other considerations that can be made where javascript is
> enabled in the user's browser.
>
> An alternative is to add onbeforeunload event handler, where that is
> supported. In the callback, user can be warned if he has a dirty page.
> "Dirty page" means that the state has changed but the changes have not
> been posted (saved) yet.

Yes, as mentioned in a follow-up, if the application is an editor of
some sort (and not just looking to preserve the UI state).