How to disable context menu in browsers ?
- Monday, June 30, 2008, 17:51
- how-to, javascript, tips and technique
- 5 comments
Today, I would like to share a fairly simple technique to disable right click menu of the website. I was using around 10-15 lines of JavaScript code to disable the menu that appears on the right click on the browser.
Here the code which you can use in the body tag of the document.
<body oncontextmenu="return false;">
As you can see, this code blocks the context menu i.e the menu which appears on the right click on the browsers. I’ve tested this code with major four browsers IE. Firefox, Opera and Safari. It worked well in all three browsers except Opera.
Popularity: 8% [?]
Related Posts
» Making accordion menu using jquery
» Help me to become the first Blogging Idol
» Useful flash Components for your website
» How to know and handle disabled javascript in browser






Also, its possible to create custom context menus for your site.
Thanks Binny for the links…
<body oncontextmenu=”return false;”> will cause the page to fail validation.
An even better way is to put
document.oncontextmenu = function() {
return false;
}
in an external JavaScript file and link to it in the head tags instead. This works in the same way, and will not cause any problem when validating code.
Which versions of IE did you check it in? I wish we could forget everything before IE7, but I’m always making sure things work in 6.