6

I'm using a website that uses the following code in their html source (as discussed here on Stack Overflow), as a way to disable right-clicking on the web page:

<body oncontextmenu="return false;">

I am assuming the easiest way to permanently and automatically bypass it (using Chrome or Firefox) - without turning off javascript altogether - is to create a simple userscript to remove this string of html code from the page (as doing so with Developer tools confirms it removes the restriction), so in the userscript effectively have it replace this string:

 oncontextmenu="return false;"

with nothing - no characters as its replacement.

Is this the best way to bypass this restriction without turning off javascript entirely (including other actually useful scripts on the domain), and if so what would be the code to do it?

2
  • 1
    most browsers should have an option to block the context menu override (in FF it seems to be in about:config dom.event.contextmenu.enabled) Nov 28 '13 at 11:24
  • Noting: it needs to be set to false to have this effect....not the (default?) true.
    – user78017
    Nov 29 '13 at 2:42
3

In Firefox, open about:config and set dom.event.contextmenu.enabled to false. That should take care of it for all websites, but it also disables some right-click features that a very few websites add.

Otherwise, the userscript for this particular website appears to be dirt simple. Here's the complete script:

// ==UserScript==
// @name     _Stop contextmenu vandalism
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// ==/UserScript==

document.body.removeAttribute ("oncontextmenu");

Just adjust YOUR_SERVER.COM/YOUR_PATH as needed.

4
  • Thank you, this all works. Mind you I had to create my own userscript code and pasting yours exactly (bar customising @include line) didn't work, had to make a new one in firefox to get lines that seemed to make it work, but the crucial line you provided, thank you!
    – user78017
    Nov 29 '13 at 2:40
  • For some reason, after migrating from Windows to Mac (Mavericks), and nothing out of the ordinary in terms of Chrome version or anything else software-wise, it doesn't work in my Mac's Chrome where it did in Windows. However, this kind script has come to the rescue and it works with those more comprehensive lines: userscripts.org/scripts/review/384729
    – user78017
    Apr 21 '14 at 15:13
  • Further update: I was also needing to get past a certain site's text selection block too, and I was trying to fool around manually at first but by the end, I'm finding this script is doing the job smoothly for me so far: userscripts.org/scripts/review/164646
    – user78017
    Apr 21 '14 at 15:40
  • Some major websites such as Mega and OneDrive use their own context menu.
    – user598527
    Apr 2 '17 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy