Where did you install Firefox from? Help Mozilla uncover 3rd party websites that offer problematic Firefox installation by taking part in our campaign. There will be swag, and you'll be featured in our blog if you manage to report at least 10 valid reports!

Шукати в статтях підтримки

Остерігайтеся нападів зловмисників. Mozilla ніколи не просить вас зателефонувати, надіслати номер телефону у повідомленні або поділитися з кимось особистими даними. Будь ласка, повідомте про підозрілі дії за допомогою меню “Повідомити про зловживання”

Learn More

Ця тема перенесена в архів. Якщо вам потрібна допомога, запитайте.

How to allow web page to override a keyboard shortcut

  • 3 відповіді
  • 1 має цю проблему
  • 1 перегляд
  • Остання відповідь від cor-el

more options

How to allow web page to override a keyboard shortcut. Currently firefox picks up the shortcut instead of the webpage...

For example I have an webpage that detects ctrl-shift-h which worked fine in version 56 but now in version 96 it brings up a "Show All History" dialog

I an doing many such things so I looking for a generic way to override firefox keyboard shortcuts

How to allow web page to override a keyboard shortcut. Currently firefox picks up the shortcut instead of the webpage... For example I have an webpage that detects ctrl-shift-h which worked fine in version 56 but now in version 96 it brings up a "Show All History" dialog I an doing many such things so I looking for a generic way to override firefox keyboard shortcuts

Обране рішення

I found a way by adding two files under the Firefox directory

    • Firefox64\defaults\pref\config-prefs.js**
   pref("general.config.filename", "config.js");    
   pref("general.config.obscure_value", 0);  
   pref("general.config.sandbox_enabled", false); 
    • Firefox64\config.js**
   let { classes: Cc, interfaces: Ci, manager: Cm  } = Components;
   let Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
   function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); }
   ConfigJS.prototype = {
    observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); },
    handleEvent: function (aEvent) {
      let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location;
      if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) {
        if (window._gBrowser) {
          let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"];
          for (var i=0; i < keys.length; i++) {
             let keyCommand = window.document.getElementById(keys[i]);
             if (keyCommand != undefined) { 
                keyCommand.removeAttribute("command"); 
                keyCommand.removeAttribute("key"); 
                keyCommand.removeAttribute("modifiers"); 
                keyCommand.removeAttribute("oncommand"); 
                keyCommand.removeAttribute("data-l10n-id"); 
             }
          }
        }
      }
    }
   };
   if (!Services.appinfo.inSafeMode) { new ConfigJS(); }

You can get a list of ids for the keys from the source by putting the following URL in your browser

   view-source:chrome://browser/content/browser.xhtml
Читати цю відповідь у контексті 👍 0

Усі відповіді (3)

more options

Try to ask advice at the Firefox CSS subreddit forum.


You would have to use an autoconfig.cfg file to disable a built-in keyboard shortcut.

You can use the Browser Toolbox to find the ID of the shortcut you want to disable or override.

more options

Вибране рішення

I found a way by adding two files under the Firefox directory

    • Firefox64\defaults\pref\config-prefs.js**
   pref("general.config.filename", "config.js");    
   pref("general.config.obscure_value", 0);  
   pref("general.config.sandbox_enabled", false); 
    • Firefox64\config.js**
   let { classes: Cc, interfaces: Ci, manager: Cm  } = Components;
   let Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
   function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); }
   ConfigJS.prototype = {
    observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); },
    handleEvent: function (aEvent) {
      let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location;
      if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) {
        if (window._gBrowser) {
          let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"];
          for (var i=0; i < keys.length; i++) {
             let keyCommand = window.document.getElementById(keys[i]);
             if (keyCommand != undefined) { 
                keyCommand.removeAttribute("command"); 
                keyCommand.removeAttribute("key"); 
                keyCommand.removeAttribute("modifiers"); 
                keyCommand.removeAttribute("oncommand"); 
                keyCommand.removeAttribute("data-l10n-id"); 
             }
          }
        }
      }
    }
   };
   if (!Services.appinfo.inSafeMode) { new ConfigJS(); }

You can get a list of ids for the keys from the source by putting the following URL in your browser

   view-source:chrome://browser/content/browser.xhtml

Змінено cor-el

more options

Note that in Firefox 117 and newer you need to remove this line:

const {Services} = Components.utils.import('resource://gre/modules/Services.jsm');

Add this line instead: const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;