Disable right click on images and other elements with JavaScript / jQuery

April 29th, 2011 by Alex Leave a reply »

This may sometimes help you defend from novice users copying images from your site. The idea is simply in putting an oncontextmenu function inside the actual tag (not by binding ‘rightclick’ event):

$(function() {
  $('img').each(function() {
    $(this)[0].oncontextmenu = function() { return false }
  });
});

First we get all image tags (same may go to any other elements: links, lists, body etc.), then we get the actual tag by getting the first element in this object, and override it’s oncontextmenu function.

This page can be found by searching for:

jquery disable image downloadjquery disable right click on imagesjquery prevent image downloaddisable right click on element



Comments are closed.