I'm using Drupal6 lightbox2 module Already i disabled right click on images in my site. But my client asking me to disable right click in the lightbox images too. And he told me that not to watermark the images. I tried by adding the script to lightbox js file but it doesn't works.
I added oncontextmenu="return false" to the image tag in lightbox js file but it disabled the right click throughout the site.
So could anyone help me in this?
Thanks in advance.
I'm using Drupal6 lightbox2 module Already i disabled right click on images in my site. But my client asking me to disable right click in the lightbox images too. And he told me that not to watermark the images. I tried by adding the script to lightbox js file but it doesn't works.
I added oncontextmenu="return false" to the image tag in lightbox js file but it disabled the right click throughout the site.
So could anyone help me in this?
Thanks in advance.
Share Improve this question edited Feb 10, 2012 at 13:18 Ranjani asked Feb 9, 2012 at 10:14 RanjaniRanjani 1531 gold badge3 silver badges12 bronze badges 4- Always post your code =) It's easier to help you if you post your code. – hasser Commented Feb 9, 2012 at 11:23
- @Alex.I'm using this script in my page.tpl file. – Ranjani Commented Feb 9, 2012 at 12:33
- @Alex.I'm using this script in my page.tpl file.<SCRIPT LANGUAGE="JavaScript"> function right(e) { var msg = "Right Click is disabled!"; if (navigator.appName == 'Netscape' && e.which == 3) { alert(msg); return false; } if (e == null){ //IE disable e = window.event; if (e.button==2) { alert(msg); return false; } } else return true; } function trap(){ if(document.images){ for(i=0;i<document.images.length;i++){ document.images[i].onmousedown = right; document.images[i].onmouseup = right; } } } </SCRIPT> – Ranjani Commented Feb 9, 2012 at 12:39
- and in the body tag I included this one.<body onLoad="trap();">.This is what worked for images in my site and not worked for lightbox images. – Ranjani Commented Feb 9, 2012 at 12:39
5 Answers
Reset to default 3Sorry, I know you don't like that answer, but you need to educate your client instead of just doing such things. Tell him that it's more important to give the user a good experience than psudo-securing the images. Also, there really is no way you can prevent users from saving images from a web page. And that's the way it's supposed to be.
Assuming that all images have a specific class, you could do something like this:
$('.lightbox_images').bind("contextmenu", function(e) {
return false;
});
http://jsfiddle/2GmLf/
EDIT
Take a look at this example using Colorbox.
I used Firebug to identify the class that the plugin applies in images which in this case is cboxPhoto
.
Also changed the bind to live.
http://jsfiddle/2GmLf/2/
(function($){
$(document).on('contextmenu', 'img', function() {
return false;
})
})(jQuery);
when light box popup open this disables the right click on images
Try
$('img').live("contextmenu",function(e){
return false;
});
Here's a working fiddle : http://jsfiddle/NRW2H/ ;
try this...
Add this attribute in your img tag inner lightbox. oncontextmenu="return false"
Like this:
<div> // lightbox container
// others div's
<img src="..." "alt="..." oncontextmenu="return false" >
I hope helps for you need
Best regards.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744226990a4564055.html
评论列表(0条)