I'm writing aWebGL game and want to use right-click as a control. However, it throws up a menu. Is it possible to disable that? I've tried
} else if (event.which == 2 || event.which == 3) { doRightClickControl(); event.preventDefault(); event.stopPropagation(); return false; }
Thanks dknaack for the hint. I got it to work like this:
window.oncontextmenu = function(event) { event.preventDefault(); event.stopPropagation(); return false; };
Right-click your Google Chrome shortcut and click Properties. Note: You have to put a space between chrome.exe before the code. It's two hyphens, and not a long em dash (–). Click OK, launch Chrome, and you'll see the right-click context menu is back to normal.
Method 3: Using JavaScript Code Another easy way to enable the right-click menu on any webpage is by using a simple code snippet. For that, navigate to the target webpage and copy + paste the following line of code in the address bar: javascript:void(document. oncontextmenu=null); and hit Enter.
Using jQuery for this purpose only is overkill. This will do the trick:
(function () { var blockContextMenu, myElement; blockContextMenu = function (evt) { evt.preventDefault(); }; myElement = document.querySelector('#myElement'); myElement.addEventListener('contextmenu', blockContextMenu); })();
myElement can be replaced with window.
Use this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> <title>disable rightclick menu - LabLogic</title> </head> <body> <script language="javascript" type="text/javascript"> document.oncontextmenu=RightMouseDown; document.onmousedown = mouseDown; function mouseDown(e) { if (e.which==3) {//righClick alert("Disabled - do whatever you like here.."); } } function RightMouseDown() { return false;} </script> </body> </html>
Tested in chrome 17, works with other new browsers as well
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With