60

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.

10 Answers 10

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

9
  • this looks promising!
    – Peter
    May 10, 2011 at 14:08
  • 10
    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. Mar 30, 2012 at 23:44
  • This worked like a charm. I was getting ready to build my own extension. Yay for research.
    – Till
    Sep 17, 2012 at 11:45
  • 11
    @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. Oct 22, 2013 at 2:02
  • 1
    @Alexander, Doesn't work. Tested on Google Docs using Chrome browser.
    – Pacerier
    Aug 20, 2016 at 2:36
19

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.

6
  • 13
    Doesn't work. Tested on Google Docs using Chrome browser.
    – Pacerier
    Aug 20, 2016 at 2: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, 2017 at 7:34
  • Doesn't work for me. Aug 11, 2018 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... Jan 25, 2019 at 9: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. Oct 29, 2019 at 22:42
5

Try

ctrl+shift+rightclick

Seems this action will invoke the native context menu.

My chrome version is 84

6
  • 1
    Javascript blocks the context menu entirely. Please do some research on websites that do this before you post an answer.
    – Razetime
    Aug 18, 2020 at 13:01
  • 1
    Does not work on Chrome 87 (Linux)
    – Brandon
    Feb 22, 2021 at 14:52
  • 1
    Worked on Firefox 86 (Linux). Mar 10, 2021 at 16:48
  • On a Mac it seems to be ctrl+cmd+right-click. Thanks for the hint. I like the idea that I can chose case by case whether to use or block the website's re-definition of the right-click. Sometimes it is convenient and sometimes it is annoying. Aug 16, 2021 at 19:41
  • This is the best answer because it doesn't involve extensions or scripts that may not work. Oct 4, 2021 at 14:58
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.

1
3

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();
1
  • The first worked like charm on firefox. I just pasted the code (without prefixing with javascript: ) to the console. May 7, 2023 at 19:52
2

I use NotScripts

EDIT:

I have switched to ScriptNo, which has more granular control

5
  • 2
    Does that let you control what javascript can and can't do on a page, or does it just block javascript altogether?
    – Peter
    May 5, 2011 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 5, 2011 at 21:44
  • 4
    yes. i want the ability to stop javascript from using mouse click events that come from my right mouse button.
    – Peter
    May 6, 2011 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. Mar 30, 2012 at 23:41
  • @TechZilla check my edit above
    – Moab
    Mar 31, 2012 at 0:20
1

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.

1
  • Thank you. This is the only one that worked out for me.
    – Xonshiz
    Feb 1 at 1:09
0

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

-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.

3
  • (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 8, 2018 at 9: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 9, 2018 at 1:06
  • document.oncontextmenu=null; doesn't work on sheets.google.com in chrome.
    – xaxxon
    Jul 10, 2018 at 21:39
-3

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

1
  • 3
    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 4, 2013 at 3:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .