How to disable right click on certain websites

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?

Marc-Olivier Titeux

Posted 2012-10-17T07:42:01.580

Reputation: 171

Have a look here, see the source code tab.

– Ankit – 2012-10-17T12:37:30.297

Good idea to point to userscript. Did not think about this one. Thanks – Marc-Olivier Titeux – 2012-10-18T07:40:09.183

@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); – Wladimir Palant – 2012-10-18T11:10:26.507

Answers

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!

Wladimir Palant

Posted 2012-10-17T07:42:01.580

Reputation: 1 101

Thanks a lot for the tip. I did not know about the SDK. It seems great to play with! – Marc-Olivier Titeux – 2012-10-18T07:41:29.633

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.

mvp

Posted 2012-10-17T07:42:01.580

Reputation: 79

1You seem to have missed the "on certain websites" part of the question. – Matthias Urlichs – 2013-04-11T15:42:35.953