How to disable context menu in browsers ?

Posted on June 30, 2008 
Filed Under how-to, javascript, tips and technique

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: 7% [?]

Enter your email address and get recent tutorials, tips, tricks and scripts of PHP, Ajax, JavaScript and CSS directly delivered to you email inbox:

Follow me on twitter at http://twitter.com/roshanbh.

Related Posts

» How to make 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

Comments

4 Responses to “How to disable context menu in browsers ?”

  1. Binny V A on July 1st, 2008 5:29 pm

    Also, its possible to create custom context menus for your site.

  2. Roshan on July 1st, 2008 5:40 pm

    Thanks Binny for the links…

  3. sporry on July 2nd, 2008 2:23 am

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

  4. Josh on July 6th, 2008 6:47 pm

    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.

Leave a Reply