Context menu disable with JQuery

I have found a ton of tutorials teaching how to disable the context menu on browsers and in all of them I have found one flaw:

Does not work with Opera

It’s an anoying situation that got me thinking and searching for a solution through most part of the day and with no luck.

The function is simple:

$(document).ready(function()
{
$(document).bind(“contextmenu”, function(e)
{
return false;
});
});

and it works with (tested):

and it does not work with (tested)

After a lot of research I have found why it does not work with Opera:

Opera (9.5) has an option to allow scripts to detect right-clicks, but it is disabled by default. Furthermore, Opera still doesn’t allow JavaScript to disable the browser’s default context menu which causes a usability conflict.

You can try to disable by disabling the mousedown event filtering only for Opera, but I do suggest a lot testing on this.

To complete just an extra note: this function does not bind the documents inside an iframe, so in this case you should complete the function by disabling the context menu in the iframe document as well.

Advertisements

About mcloide

Making things simpler, just check: http://www.mcloide.com View all posts by mcloide

2 responses to “Context menu disable with JQuery

  • where does this script go?

    Hi,
    I’m new to developing and want to make sure no one can lift my paintings. So where do I put this script? In the body?? Please help, as I love that one script does all the popular browsers, most versions.
    Thanks,
    Laura

    • mcloide

      Hi

      Just add it in the header or footer of the site and make sure the script is inside the $(document).ready() { }; function.

      If you don’t have JQuery installed, to it so, so you can use the JQuery library to load this script up. To download and install JQuery go to http://www.JQuery.com

      This script will ensure that people can’t download your pictures via right click, therefore there other ways to do it so. The best solution is still using a watermark on each picture.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: