3

I'm currently using Shadowbox.js to my gallery and I want to disable the right click when the visitor views the image in full size. How can I accomplish this?

Thanks in advance.

Airikr
  • 6,258
  • 15
  • 59
  • 110
  • why would you want to do this? – Alp Jun 30 '12 at 02:08
  • I want to force the visitor to hit the download link for the image instead of save the image from the context menu. In that way I can handle every downloads and have more control over who have the image on their computer. – Airikr Jun 30 '12 at 02:11
  • people can still look at the source code. and they don't like to be controlled. at least that obviously – Alp Jun 30 '12 at 02:13
  • 1
    You can disable it completely fairly easily: [Jquery/JS prevent right click menu in browsers](http://stackoverflow.com/questions/4920221/jquery-js-prevent-right-click-menu-in-browsers) – Brandon Boone Jun 30 '12 at 02:15
  • 1
    @Alp: Many users don't know that they can look in the source code and take the image from there. I know that and they will be notified that their action will be logged once they click on the download link. – Airikr Jun 30 '12 at 02:16

1 Answers1

3

You can do the following to specifically target Shadowbox.js and leave the context menu intact on the rest of the page.

jQuery 1.7+

$(function(){
    $('#sb-wrapper').on('contextmenu', function(){return false;});
});

jQuery 1.6

$(function(){
    $('#sb-wrapper').live('contextmenu', function(){return false;});
});

Native

//Should be executed as part of the window.onload method 
document.getElementById('sb-wrapper').oncontextmenu = function(){return false;}

Demo

Execute the Native statement in the Chrome's console on http://www.shadowbox-js.com/

Brandon Boone
  • 16,281
  • 4
  • 73
  • 100
  • Thanks! The native solution worked better than the jQuery for some reason :) – Airikr Jun 30 '12 at 02:31
  • Glad it worked! Could be your version of jQuery. I added some more clarification. I wasn't able to test though and you can always use [bind](http://api.jquery.com/bind/) if both of the above fail. – Brandon Boone Jun 30 '12 at 02:36
  • I'm glad too :) I have the latest jQuery version (1.7.2). – Airikr Jun 30 '12 at 02:40
  • I tested the jQuery variant of your solution and `live` worked perfectly. Thanks once again! – Airikr Jun 30 '12 at 02:55