jhmplondon
asked on
Disable right mouse click context menu only on images.
Hi,
I have this code to disable right mouse click on my pages and it works fine, however I need to modify it, so it disables only context menu on images, rest of the site should have right click enabled - must work in all modern browsers.
Thanks
Tom
I have this code to disable right mouse click on my pages and it works fine, however I need to modify it, so it disables only context menu on images, rest of the site should have right click enabled - must work in all modern browsers.
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
document.onmousedown = disable_right_click;
function disable_right_click (e)
{
which=(document.all)?event.button:e.which
if ( which == 2 || which == 3 )
{
window.returnValue=false;
it=true
return false ;
}
return true ;
}
//-->
</SCRIPT>
</HEAD>
<body oncontextmenu="return false">
</BODY>
</HTML>
Thanks
Tom
I must admit I don't have a script to do that but my only query is to what you're trying to achieve as there is no way to stop someone from copying the images off your site. Disabling javascript will get around your script. Using the keyboard shortcut for the context menu gets around it. Viewing the source and finding the direct URL to the image will get around it as the main page won't be loaded. Taking a screenshot, saving the page locally. etc., all get around this. Put a watermark in your images if they are images for sale. If you don't want them taken from your site, then the only sure fire way I'm afraid is to not put them on the web.
Lee
Lee
I must admit I don't have a script to do that but my only query is to what you're trying to achieve as there is no way to stop someone from copying the images off your site. Disabling javascript will get around your script. Using the keyboard shortcut for the context menu gets around it. Viewing the source and finding the direct URL to the image will get around it as the main page won't be loaded. Taking a screenshot, saving the page locally. etc., all get around this. Put a watermark in your images if they are images for sale. If you don't want them taken from your site, then the only sure fire way I'm afraid is to not put them on the web.
Lee
Lee
Blocking the context menu in the body tag is easily circumvented:
http://javascript.about.com/library/blnoright.htm
http://javascript.about.com/library/blnoright.htm
ASKER
lsavidge:
I know it's always possible to copy image, in my case I have jQuery modal box open once someone uses right mouse button with code how to embed this image elsewhere (with the link back), however at the moment if someone right click on the image both open - my modal box and context menu, if I disable context menu on the whole page they are then not able to copy the embed code from modal box... That's why I need to disable it only for images.
I script I attached in my first post works fine - so I now how to block it on whole page - but as mentioned above - I need to block it only over images.
This thread exactly shows what I need - however it doesn't work in Safari:
https://www.experts-exchange.com/questions/24833830/Disable-right-click-for-all-images-on-a-page-but-not-non-image-parts-of-the-page.html?sfQueryTermInfo=1+10+30+click+disabl+imag+right
So I'd really like to keep the one I have attached in my first post, but add the function to block it only for images.
I know it's always possible to copy image, in my case I have jQuery modal box open once someone uses right mouse button with code how to embed this image elsewhere (with the link back), however at the moment if someone right click on the image both open - my modal box and context menu, if I disable context menu on the whole page they are then not able to copy the embed code from modal box... That's why I need to disable it only for images.
I script I attached in my first post works fine - so I now how to block it on whole page - but as mentioned above - I need to block it only over images.
This thread exactly shows what I need - however it doesn't work in Safari:
https://www.experts-exchange.com/questions/24833830/Disable-right-click-for-all-images-on-a-page-but-not-non-image-parts-of-the-page.html?sfQueryTermInfo=1+10+30+click+disabl+imag+right
So I'd really like to keep the one I have attached in my first post, but add the function to block it only for images.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it works
add this to body tag
<body oncontextmenu="return false;">
refer
https://www.experts-exchange.com/expertsZone.jsp