58

I despise web sites that hijack my right mouse button via javascript. Other browsers ( like firefox) allow me to block sites from doing this. Does chrome have such an option, or does it leave me at the mercy of annoying web site designers?

I don't want to turn off javascript completely. I just want to block javascript from taking over my right mouse button. Firefox lets you stop javascript from doing specific things like this. I am trying to find out if Chrome does as well. I am going to assume it does not at this point.

mit
  • 1,533
  • 15
  • 29
Peter
  • 763
  • 2
  • 7
  • 12

10 Answers10

23

Try this Chrome extension, it specifically stops websites from blocking the right click button.

Enable Right Click

https://chrome.google.com/webstore/detail/enable-right-click/hhojmcideegachlhfgfdhailpfhgknjm

cmbuckley
  • 124
  • 7
Alexander Lai
  • 788
  • 4
  • 5
  • this looks promising! – Peter May 10 '11 at 14:08
  • 9
    It's really disappointing chrome requires an extension for this, but it does address the problem. Voted up answer, but still looking for any better solution. – J. M. Becker Mar 30 '12 at 23:44
  • This worked like a charm. I was getting ready to build my own extension. Yay for research. – Till Sep 17 '12 at 11:45
  • @TechZilla I'm sorry but it has nothin gto do with Chrome. It's the JavaScript teeling the browser not to "do" anything when right clicking. You can override this though by going into Chrome settings and disabling Javascript scripts. And walla, you can right click. – Karl Morrison Oct 21 '13 at 21:29
  • 10
    @Karl Morrison: I think you may have misunderstood my criticism, I wasn't criticizing chrome for disabling the right-click menu. I was irritated that chrome doesn't provide a method to selectively disable Javascript functions. Also want to mention disabling JavaScript will render many sites nonfunctional. Firefox provides a "Disable or replace context menus" Javascript option. – J. M. Becker Oct 22 '13 at 02:02
  • Link is broken. – Joseph Garvin Oct 06 '14 at 21:10
  • @JosephGarvin updated to a different link. – cmbuckley Oct 06 '14 at 21:12
  • 1
    @Alexander, **Doesn't work.** Tested on Google Docs using Chrome browser. – Pacerier Aug 20 '16 at 02:36
  • @Pacerier maybe google treating google docs not as a website but a chrome app or extension makes it so other extensions cannot interfere – My1 Aug 30 '21 at 20:45
21

Press F12 to bring Google Chrome Developers Tools out and navigate to Console tab and run below command:

document.oncontextmenu=null;

It should bring most of the context menu back.

It should work for Firefox as well.

Of course on Firefox you could just use Shift + right-click to bypass the JS context menu.

Run5k
  • 15,723
  • 24
  • 49
  • 63
Shi B.
  • 338
  • 2
  • 6
  • 12
    Doesn't work. Tested on Google Docs using Chrome browser. – Pacerier Aug 20 '16 at 02:33
  • @Pacerier I don't know what voodoo magic did Google cast on Docs, it is not utilising oncontextmenu and thus my solution doesn't work. However, the other method I mentioned should work under Chrome as well, use Shift + right click to bring up the original context menu. – Shi B. Nov 29 '17 at 07:34
  • Doesn't work for me. – Ben Wheeler Aug 11 '18 at 21:59
  • 3
    To counter the "doesn't work" comments - this does work, it may not work for every web site, but the answer from @shi-b does work... – Robert Swift Jan 25 '19 at 09:25
  • It'll be dependent on what dom element the contextmenu eventlistener was attached to. Often it'll be document but it could be attached to any element. – Scott Christopherson Oct 29 '19 at 22:42
  • watch out, this may have malware. Check the comments of https://stackoverflow.com/questions/64389426/how-to-determine-why-the-connected-host-is-different-from-request-url-in-chrome – CrazyVideoGamer Jul 14 '21 at 15:45
  • This only works if the website overwrites the `oncontextmenu` function-property - most websites today use `addEventListener` which cannot (easily) be manipulated by other scripts, only the Developer Tools. It is unfortunate that the DOM doesn't let us enumerate and remove event-listeners. Grumble. – Dai Sep 30 '21 at 01:20
5

Try

ctrl+shift+rightclick

Seems this action will invoke the native context menu.

My chrome version is 84

eforlina
  • 59
  • 1
  • 2
4

I found an acceptable solution, from About.com. It's a small bookmarklet, which by nature must be clicked to force disable this particular annoying JS. However I find it better than the Firefox style option, as many sites need right-click controlling JS. For example Google Docs etc...

At least I don't need to waste resources storing an additional extension in memory. You can watch how chrome stores extensions with its task-manager, of coarse you need an extension installed to watch.

tomasz86
  • 107
  • 4
J. M. Becker
  • 633
  • 6
  • 15
  • The code is `javascript:void(document.onmousedown=null);void(document.onclick=null);void(document.oncontextmenu=null)`. Unfortunately it **doesn’t work** for me in Netflix with Google Chrome. But https://chrome.google.com/webstore/detail/allow-right-click/hompjdfbfmmmgflfjdlnkohcplmboaeo **worked**. – Aaron Thoma Sep 01 '18 at 04:38
2

This bookmarlet works in Google sites/Youtube as of Aug 2019 (tested in Chrome and Firefox):

javascript: function enableContextMenu(aggressive = false) { void(document.ondragstart=null); void(document.onselectstart=null); void(document.onclick=null); void(document.onmousedown=null); void(document.onmouseup=null); void(document.body.oncontextmenu=null); enableRightClickLight(document); if (aggressive) { enableRightClick(document); removeContextMenuOnAll("body"); removeContextMenuOnAll("img"); removeContextMenuOnAll("td"); } } function removeContextMenuOnAll(tagName) { var elements = document.getElementsByTagName(tagName); for (var i = 0; i < elements.length; i++) { enableRightClick(elements[i]); } } function enableRightClickLight(el) { el || (el = document); el.addEventListener("contextmenu", bringBackDefault, true); } function enableRightClick(el) { el || (el = document); el.addEventListener("contextmenu", bringBackDefault, true); el.addEventListener("dragstart", bringBackDefault, true); el.addEventListener("selectstart", bringBackDefault, true); el.addEventListener("click", bringBackDefault, true); el.addEventListener("mousedown", bringBackDefault, true); el.addEventListener("mouseup", bringBackDefault, true); } function restoreRightClick(el) { el || (el = document); el.removeEventListener("contextmenu", bringBackDefault, true); el.removeEventListener("dragstart", bringBackDefault, true); el.removeEventListener("selectstart", bringBackDefault, true); el.removeEventListener("click", bringBackDefault, true); el.removeEventListener("mousedown", bringBackDefault, true); el.removeEventListener("mouseup", bringBackDefault, true); } function bringBackDefault(event) { event.returnValue = true; (typeof event.stopPropagation === 'function') && event.stopPropagation(); (typeof event.cancelBubble === 'function') && event.cancelBubble(); } enableContextMenu();

For peskier sites, set/pass aggressive to true (this will disable most event handlers and hence disable interaction with the page):

javascript: function enableContextMenu(aggressive = true) { void(document.ondragstart=null); void(document.onselectstart=null); void(document.onclick=null); void(document.onmousedown=null); void(document.onmouseup=null); void(document.body.oncontextmenu=null); enableRightClickLight(document); if (aggressive) { enableRightClick(document); removeContextMenuOnAll("body"); removeContextMenuOnAll("img"); removeContextMenuOnAll("td"); } } function removeContextMenuOnAll(tagName) { var elements = document.getElementsByTagName(tagName); for (var i = 0; i < elements.length; i++) { enableRightClick(elements[i]); } } function enableRightClickLight(el) { el || (el = document); el.addEventListener("contextmenu", bringBackDefault, true); } function enableRightClick(el) { el || (el = document); el.addEventListener("contextmenu", bringBackDefault, true); el.addEventListener("dragstart", bringBackDefault, true); el.addEventListener("selectstart", bringBackDefault, true); el.addEventListener("click", bringBackDefault, true); el.addEventListener("mousedown", bringBackDefault, true); el.addEventListener("mouseup", bringBackDefault, true); } function restoreRightClick(el) { el || (el = document); el.removeEventListener("contextmenu", bringBackDefault, true); el.removeEventListener("dragstart", bringBackDefault, true); el.removeEventListener("selectstart", bringBackDefault, true); el.removeEventListener("click", bringBackDefault, true); el.removeEventListener("mousedown", bringBackDefault, true); el.removeEventListener("mouseup", bringBackDefault, true); } function bringBackDefault(event) { event.returnValue = true; (typeof event.stopPropagation === 'function') && event.stopPropagation(); (typeof event.cancelBubble === 'function') && event.cancelBubble(); } enableContextMenu();
Chema
  • 436
  • 3
  • 8
2

I use NotScripts

EDIT:

I have switched to ScriptNo, which has more granular control

Moab
  • 58,044
  • 21
  • 113
  • 176
  • 1
    Does that let you control what javascript can and can't do on a page, or does it just block javascript altogether? – Peter May 05 '11 at 19:23
  • It blocks js by domain, each domain selectable by you, depends on what you mean by hijacks your right click, do you mean it changes your context menu? – Moab May 05 '11 at 21:44
  • 3
    yes. i want the ability to stop javascript from using mouse click events that come from my right mouse button. – Peter May 06 '11 at 18:51
  • Another solution non grata, but a big step above completely disabled JS. I've used FireFox noscript, which is still hardly usable, but Chrome notscripts is actually even worse. They both require a grip of manual intervention, and basically just enable/disable JS completely per domain. If you want to solve the problem, of fine-grained specific JS DOM disabling, both do not suffice. Although by skin of the teeth, it's just good enough to avoid my downvote. – J. M. Becker Mar 30 '12 at 23:41
  • @TechZilla check my edit above – Moab Mar 31 '12 at 00:20
0

This works on my OS X Chrome Version 88.0.4324.96: open chrome://flags/#hardware-media-key-handling and set to Disabled.

0

Firefox

ctrl+shift+rightclick.

This will show the context menu.

Chrome

Paste this to the console (F12) and press Enter:

document.addEventListener("contextmenu", (e)=>e.stopPropagation(), true);

Then right-click on the page.

Marinos An
  • 778
  • 6
  • 13
-1

Building on Shi B. solution I got a reliable way of solving the problem on Google Chrome.

(1) Get custom-javascript-for-web plugin for Chrome.

(2) Paste document.oncontextmenu=null; into the plugin's console.

Works like a charm.

Karolis
  • 99
  • 2
  • (I know this is old, but I'm too curious to let it be) Why in the world would you use that instead of the default console for this? To me it just looks like a harder way to achieve exactly the same. – DennisK Mar 08 '18 at 09:44
  • 1
    in my case, I was coming back to the same website (Dropbox Paper). So it automatically had that script executed for one website. Fortunately, the company fixed it – Karolis Mar 09 '18 at 01:06
  • `document.oncontextmenu=null;` doesn't work on sheets.google.com in chrome. – xaxxon Jul 10 '18 at 21:39
-2

You can easily enable/disable or allow/block javascript on any website in Google chrome. Just click on paper sign before the site url. Under permisions you will see javescript, click down arrow you will see a menu, select "Always block on this site" and reload web page so changes can take effect.

Hope this will help.

Here is link to image.

https://www.facebook.com/photo.php?fbid=10201389704683447&l=5294c0075e

  • 2
    I am not trying to block all javascript. I only want to block javascript from intercepting right mouse clicks. Some browsers give you that option. – Peter Sep 04 '13 at 03:15