Disabling Firefox keyboard shortcuts with JavaScript

First off, let me just say I feel really stupid for posting this. It seems like I stumbled onto something for the first time that should be common knowledge for a JavaScript developer.  However, I am still making the post because I find this to be rather strange.  Using the event ‘preventDefault’ method, you can completely disable Firefox’s built in keyboard shortcuts.  If you click on the following js bookmarklet:

ruin my browser!

You won’t be able to pop firebug up with f12, ctrl+t yourself a new tab, get yourself a fresh version of the page with f5, and you won’t even be able to view the source. When I ran into this for the first time, I thought my computer was fucked up.

Apparently, this is also just Firefox. I just tested it in IE and Chrome, and it appears to do nothing. Is this a XUL thing?

Does anyone else find this to be strange or annoying? Is this surprising or am I stupid? It just seems like this shouldn’t happen.

trackback

Tags: , , , , 6 responses »
  1. nocash's gravatar

    Shuts down my keys as well. I always thought this level of user annoyance was reserved for sites that use Flash.

  2. me's gravatar

    does not work anymore. too bad, that would have fixed my browser… i want those keyboard shortcuts disabled all of the time. they interfere with other shortcuts on my Mac, like the one for Megazoomer

  3. atom's gravatar

    Still appears to work in linux and windows, i suspect that for whatever reason macs aren’t good enough to fail properly.

  4. SamGoody's gravatar

    Actually, this is good. Just used wrong.

    I have developed a wysiwyg editor, and need to be able to respond to keyboard shortcuts. Once javascript must give me that level of control (and in all browsers) there is no reason to make it difficult to setup.

    Mootools has all this built in: there is no difference between overiding the ctrl+b or overiding all keyboard shortcuts.

  5. verne miller's gravatar
    verne miller Says:

    I clicked on the bookmarklet.It worked but how do I get the shortcuts back?

  6. atom's gravatar

    you could not have typed that comment if your keys were disabled. i suspect you are confused.

Leave a Reply

ok to use:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

bonus!

If you want to post code, you can use:

<pre lang="[language]">[code]</pre>

Where [language] is a valid geshi language type, and where [code] is your code.