Prevent the Backspace key from Navigating in Internet Explorer

I’m a big fan of the Prototype Javascript library and use it almost exclusively.  One thing I’ve noticed about stopping event bubbling/propagation is that  Event.stop(event) doesn’t always work as I expect.   This is one of the rare cases where I will use straight Javascript instead.

One of my least favorite “features” of Internet Explorer is the backspace key’s default back button behavior.  If the user thinks that an input field has focus and tries to delete some input, it’s easy to navigate back to the wrong page; very frustrating.

I use the following lines of code to ensure that events are stopped in their tracks.

window.event.cancelBubble = true;

// or

window.event.returnValue = false;

This is certainly not new or revolutionary; in fact, it’s very basic Javascript programming.  However, I suspect there are more people out there who, like me, have been learning Javascript “backwards”  – starting with advanced frameworks that provide all the basics, insulating one from lower level drudgery.  Discovering this little gem was one of many “duh” moments in programming for me.  Better to have learned it late than never.

Advertisements
This entry was posted in Code and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s