How to disable context menu in browsers ?

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.

7 thoughts on “How to disable context menu in browsers ?

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

  2. Thanks Binny for the links…

  3. sporry

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

  5. rif

    how to disable right click by using .htaccess ?

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>