• Resolved janwyl

    (@janwyl)


    Hi

    Really hope you can help with this as the plugin is great and I want to use it very much. The site I am building is for photographers and as a rule they are all paranoid about having their images stolen. (I should know as I am one too.) I know disabling the right click does nothing to prevent anyone with the most basic understanding of html, but the point is not to make it so easy people think “Well why not, just this once, since all I have to do is right click and Save As…”.

    So I am trying to disable the right click when an image has been opened in fancybox overlay. The jQuery code I am using is

    $('.fancybox').fancybox({
    		onComplete: function() {
    		$('fancybox-img').bind('contextmenu',function(e){
    			alert("Right-click menu disabled to prevent image copying");
    			return false;
    			});
    		}
    	});

    I am a novice with jQuery so not really sure what I’m doing wrong. Tried various variations of the above but it seems that it’s just not picking up the onComplete event (or any event that I try).

    You can see how I’m tyring to use it at https://www.ratedfotos.com or for a simple example that isn’t triggered by a slider at https://www.ratedfotos.com/test-page/

    Any pointers would be massively appreciated!

    Thanks
    Jon

    https://www.ads-software.com/plugins/easy-fancybox/

Viewing 3 replies - 1 through 3 (of 3 total)
  • For sites like yours I usually just add this to the theme footer:

    <script type="text/javascript">
    jQuery('body').delegate('img,#fancybox-content','contextmenu',function(){return false;});
    jQuery('body').delegate('img,#fancybox-content','dragstart',function(){return false;});
    </script>

    which simply disables both the context menu and the drag-drop action (did you thingk about that one?) on all images (outside fancybox) and all fancybox content. However, if your theme uses Infinite Scroll or other methods of ajax/lazy loading, then this might not work for all images…

    A more complete code snippet that works with Infinite Scroll would be something like:

    <script type="text/javascript">
    if (typeof jQuery == 'undefined') { document.write('<'+'script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">'); }
    jQuery(document).on( 'ready post-load', function($){
        $('body').delegate('img,#fancybox-content','contextmenu',function(){return false;});
        $('body').delegate('img,#fancybox-content','dragstart',function(){return false;});
    }
    </script>

    Thread Starter janwyl

    (@janwyl)

    Fabulous. Works great. Yes I had the dragstart in mind ?? already had that and the right click disabled on the non-fancybox images and was going to add it in.

    Thanks v much for such a quick and helpful response. 5 starred and bought the Pro version as a result. Not sure I need it but since you deserve a donation then I figured I may as well just get the Pro version ??

    All the best
    Jon

    Hi Jon, that is very kind of you. Thanks! I hope the extra options serve you and in any case you will be able to get support via the pro forum as well now ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disabling right click’ is closed to new replies.