How to prevent websites from hijacking keyboard shortcuts

Keyboard shortcuts are a great way of speeding up certain operations in the web browser of choice. Ctrl-t opens a new tab, Ctr-s saves the displayed content to the local system, and Ctrl-l moves the cursor to the browser's address bar.

Sometimes however these shortcuts won't work and the core reason for this is that the website you are on hijacked it. Without going into too many technicalities: websites can override shortcuts by using JavaScript.

A basic example is Gmail where the shortcut /, which should open the on-page search in Firefox, moves the cursor to the site's search field instead.

A long standing bug on Bugzilla addresses the issue in regards to Firefox, but there is no solution in sight. Considering that all browsers share the issue, it is fair to say that this is something that browser developers need to address rather sooner than later.

There are methods to block websites from overriding shortcuts.

Disabling JavaScript

This is without doubt the easiest option of them all, but also the one that may impact how sites are displayed in the browser. Since most websites hijack shortcuts by using JavaScript, disabling JavaScript prevents them from doing so.

Depending on which browser you use you may either disable JavaScript in the browser's options, or use an extension to do so.

I like NoScript for Firefox for this for example as it blocks scripts on most sites automatically after installation. If you find NoScript to invasive, you can try YesScript which allows all but the ones you block.

Chrome users can use ScriptBlock for example to do the same thing.

Disabling JavaScript can render some site functionality or sometimes even the whole site unusable.

Turning it off on the site

keyboard shortcuts

Some websites offer controls to turn the keyboard shortcut handling on or off. On Gmail for instance, it is possible to turn off keyboard shortcuts so that nothing is hijacked anymore by the site.

It needs to be noted that this is not a universal solution though as most sites don't offer preferences this this. To do so on Gmail, simply open this link which leads to the general settings. Scroll down until you find keyboard shortcuts listed there and switch the preference from on to off.

Try an alternative

Sometimes web browsers offer multiple shortcuts for the same functionality. Firefox users can open the on-page search with Ctrl-f, F3, or / for example and if one of the shortcuts is blocked, you can try to use a different one if it exists to still use it.

Most of the time though, multiple shortcuts may not be provided.

This method is problematic for another reason: you may not want to use a different shortcut just for a specific website. If you always use Ctrl-f to open the search in the browser, you may not want to use F3 instead.

Scripts and add-ons

Scripts and add-ons may have been created to resolve some of the issues. The Firefox add-on free-control for example blocks websites from overtaking Ctrl-PageUP and Ctrl-PageDOWN shortcuts, while a userscript posted on the Superuser website can handle any Ctrl-powered shortcut.

For the later to work for other shortcuts besides Ctrl-s and Ctrl-t, you need to manipulate the script by adding keycodes that you find on this page to it.

Now You: Is there another method to block websites from stealing keyboard shortcuts? Please share it in the comment section below.

Summary
Article Name
How to prevent websites from hijacking keyboard shortcuts
Author
Description
Some Internet sites take over keyboard shortcuts from the browser and map other functionality to it. Find out how to prevent this.
Please share this article

facebooktwittergoogle_plusredditlinkedinmail


Responses to How to prevent websites from hijacking keyboard shortcuts

  1. dow August 15, 2014 at 11:11 am #

    The most annoying hotkey hijack by far is Youtube! I've seen several bug posts relating to that for Firefox, spanning many years back. But no solution so far.

    • fokka August 15, 2014 at 5:32 pm #

      this. afaik this is because, as soon as you click the play button or anything else in the player, it's the flash plugin that's in focus, so all shortcuts get sent to flash instead of firefox. really annoying.

      edit: it seems that opting for the html5 player gets rid of that annoyance. at least in my case the html5 player is completely buggy and useless though, so that's not an option for me atm.

      • dow August 16, 2014 at 4:14 pm #

        Yeah, Flash steals focus. And has been doing so forever. One more good reason to wish for the demise of Flash I guess.

  2. Tom Hawack August 15, 2014 at 1:08 pm #

    What bothers me the most, though this appears on very few sites, are context menu and text selection disabled. Bookmarklets are available to restore both. I've made ad add-on which delivers a toolbar button with one javascript for both annoyances : click and both annoyances are off. Maybe do similar bookmarklets exist for keyboard shortcuts hijacking.

    Generally speaking, how not to be annoyed by domains who have the nerve to seize a user's browser tools for themselves? Whatever bothers a user's move on a website (for legitimate reasons) is moreover counter-productive.

  3. Sylvio Haas August 16, 2014 at 6:12 pm #

    Can shortcut keys programmed on Phrase Express be stolen too? Thank you.

  4. Elben August 17, 2014 at 5:50 pm #

    Thank you for YesScript. I was looking for some plugin that could disables scripts only on specified websites.

Leave a Reply