12
document.addEventListener('contextmenu', function (e) {
    e.preventDefault()
    e.stopPropagation()
    e.returnValue = false
    e.cancleBubble = true
})

No way?

Edit: document.oncontextmenu = null does not work.

P.S. I cannot have the reference of the listener function since I am not the owner of the site preventing the context menu.

Chungmin Lee
  • 2,320
  • 2
  • 18
  • 19
  • what do you mean by "ethics"? – Chungmin Lee Jun 02 '10 at 22:20
  • 8
    Sites that purposely disable the context menu deserve to have their scripts suppressed or not ran, in my opinion. (I use NoScript.) I often navigate by right-clicking and selecting Back or Forward. There is nothing unethical about wanting the context menu to work. The site author disabling it in the first place is stupid. – JYelton Jun 02 '10 at 22:23
  • 1
    Have you tried `document.oncontextmenu = null;`? – Doctor Kicks Jun 02 '10 at 22:44

3 Answers3

23

I use my bookmarklet in such cases:

javascript:(function(w){
    var arr = ['contextmenu','copy','cut','paste','mousedown','mouseup','beforeunload','beforeprint'];
    for(var i = 0, x; x = arr[i]; i++){
        if(w['on' + x])w['on' + x] = null;
        w.addEventListener(x, function(e){e.stopPropagation()}, true);
    };
    for(var j = 0, f; f = w.frames[j]; j++){try{arguments.callee(f)}catch(e){}}})(window);
user1727984
  • 249
  • 2
  • 5
  • This one worked fine. Just had to limit the options to 'contextmenu'. – ThiagoPonte Apr 27 '16 at 12:36
  • `'copy','cut','paste','mousedown','mouseup','beforeunload','beforeprint'` do not work though `'contextmenu'` works for site `https://verification.taxofficemanagement.gov.bd/` – Learner Feb 01 '23 at 04:11
4

If you are really desperate, try adding this before the addEventListener is called. It works in both FF and Chrome. I didn't check anything else.

document.superListener = document.addEventListener;
document.addEventListener = function(type, listener, useCapture){
    if(type != 'contextmenu')
        document.superListener(type, listener, !!useCapture);
};

It may not be the best way to do things, but it should be the job done on your specific example :)

Gordon Tucker
  • 6,653
  • 3
  • 27
  • 41
0

Rather than disabling the context menu, why don't you assign the right click event?

http://abeautifulsite.net/2008/05/jquery-right-click-plugin/

Matrym
  • 16,643
  • 33
  • 95
  • 140