1

I am not asking this question from a web developer but from an end-user.

I am using several web sites (google drive, evernote and so on) that have context menu that activates upon a right click event. However, on my browser (Firefox), if I right click it opens my navigator context menu on top of the context menu implemented by the web developer(s) of the website. If I right click a second time, then the navigator context menu disapears, leaving space for the web app context menu.

How can I, as an end-user, disable right clicks on specific websites? And if possible, I would like to have this possibility "on-demand", ie being able to reactivate right clicks when I want to.

Is there an existing addon or a javascript tricks somewhere for this? And if not, which direction should I follow to code something like this?

3
  • Have a look here, see the source code tab.
    – Ankit
    Commented Oct 17, 2012 at 12:37
  • Good idea to point to userscript. Did not think about this one. Thanks Commented Oct 18, 2012 at 7:40
  • @Lamb: Wow, that script is horrible. When was it written, in the 90s? For reference: proper solution would be document.addEventListener("contextmenu", function(event) {event.preventDefault();}, false); Commented Oct 18, 2012 at 11:10

3 Answers 3

2

I am not aware of any extensions to achieve this but creating one wouldn't be hard. You could use the Add-on SDK, most easy to be used via Add-on Builder that is a web application to create SDK-based extensions. The high-level SDK modules don't give you direct access to the browser window however, you have to use the largely undocumented window-utils module for that. The following code in main.js works:

var icons = {
  "enabled": "http://www.mozilla.org/favicon.ico",
  "disabled": "http://www.mozilla.org/media/img/favicon.ico"
};

function disableContextMenu(event)
{
  event.preventDefault();
}

require("widget").Widget({
  id: "disable-context-menu",
  label: "Disable Context Menu",
  contentURL: icons.enabled,
  onClick: function(view)
  {
    var window = require("window-utils").activeBrowserWindow;
    var menu = window.document.getElementById("contentAreaContextMenu");
    if (this.contentURL == icons.enabled)
    {
      menu.addEventListener("popupshowing", disableContextMenu, false);
      this.contentURL = icons.disabled;
    }
    else
    {
      menu.removeEventListener("popupshowing", disableContextMenu, false);
      this.contentURL = icons.enabled;
    }
  }
});

It's really as simple as that - adding this event handler to the context menu disables it, removing that event handler switches it back on. The extension also switches icons to indicate its state. That's it. Of course, if you want to keep the state per-tab then you will need a more elaborate logic. Good luck!

1
  • Thanks a lot for the tip. I did not know about the SDK. It seems great to play with! Commented Oct 18, 2012 at 7:41
0

Go to the Content tab under Tools > Options. Click on the Advanced... button next to the Enable JavaScript checkbox. This opens the Advanced JavaScript Settings dialog box. Toggle the checkbox option Disable or replace context menus in the list presented.

1
  • 1
    You seem to have missed the "on certain websites" part of the question. Commented Apr 11, 2013 at 15:42
0

FYI, For newer versions of FireFox (in case someone is trying to figure this out like I was)

The menu option Tools > Options > Content is not available on newer FireFox releases like 78.9. However, you can go to about:config and search for dom.event.contextmenu.enabled, set it to True and then websites can selectively replace the right click context menu.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .