Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Have a look here, see the source code tab. –  Lamb Oct 17 '12 at 12:37
    
Good idea to point to userscript. Did not think about this one. Thanks –  mot Oct 18 '12 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); –  Wladimir Palant Oct 18 '12 at 11:10
add comment

2 Answers 2

up vote 2 down vote accepted

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!

share|improve this answer
    
Thanks a lot for the tip. I did not know about the SDK. It seems great to play with! –  mot Oct 18 '12 at 7:41
add comment

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.

share|improve this answer
    
You seem to have missed the "on certain websites" part of the question. –  Matthias Urlichs Apr 11 '13 at 15:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.