The most popular way bloggers use in protecting their site content is by disabling right click on the whole blog content, but this action makes some loyal readers to feel depress with limited functions associated to the right click such as open link in new window, bookmark this link, reload and back. But you can still protect your blog images by disabling right click on only images and not the whole blog, which still makes sense.
This effect can be apply to a single image or the whole images on your blog, using a few line of code. both the two hacks will be shared in this tutorial, and for a demo of this hack, simply click on the image below, and see what we are talking about. Cool right?
In other to disable right click on a single image, you will need to add a context menu event handler code into the image tag. The following code is the code you need to insert into your image tag.
Now in your post editor, simply switch to HTML mode when your are about to disable an image. The image tag will look as follow:
Adding the context menu snippet into to the image tag, the final result will look as follow:
You can change Image protected to your preferred text as it is the alert text that will appear when a reader click on the protected image.
- Go to Template > Edit HTML > Proceed
- Use ctrl F to find </head> and paste the following code after/below </head>
//<![CDATA[
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Disable context menu on images by www.realcombiz.com
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
function nocontext(e) {
var clickedTag = (e==null) ? event.srcElement.tagName : e.target.tagName;
if (clickedTag == "IMG") {
alert(alertMsg);
return false;
}
}
var alertMsg = "Image context menu is disabled";
document.oncontextmenu = nocontext;
//]]>
</script>
The code above will disable context menu on all your blog images and replace it with an alert box.
Hope you love this new hack?
Suggestion/comments are highly welcome, as we love to hear from you and feel free to share it with friends and followers using the share buttons.
*Please confirm the email sent to your inbox after clicking "Sign Up!".
gud work man..its work fine.
ReplyDeletebut no use of it unless u disable the image url link.
it only disable right click not left click. :-p
Thanx alot man, its real work
ReplyDeleteThanks for this post. I think this is a good idea to protect our site. Is there something for the WordPress too?
ReplyDeletewebsite design
Yeah, it worked, thanks you so much realcombiz
ReplyDelete