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.

Popularity: 8% [?]

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

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

5 Comments on “How to disable context menu in browsers ?”

  • Binny V A wrote on 1 July, 2008, 17:29

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

  • Roshan wrote on 1 July, 2008, 17:40

    Thanks Binny for the links…

  • sporry wrote on 2 July, 2008, 2:23

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

  • Josh wrote on 6 July, 2008, 18:47

    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.

Trackbacks

  1. Recent Links Tagged With "contextmenu" - JabberTags

Write a Comment

 


Copyright © 2009 Roshan Bhattarai's Blog. All rights reserved.
Powered by WordPress.org, Custom Theme and ComFi.com Calling Card Company.