Disabling right click or context menu is one of the more popular ways to prevent images from being stolen from a blog.
While it is effective to some extent in deterring casual image theft, it also frustrates honest readers by denying them access to many useful functions associated the right click such as going Back, page Reload, Bookmark and Open Link In New
Window.
The better way would be to disable right click only on images. After all it’s the images they’re trying to protect, so this method is more appropriate to the task and more importantly it’s far less annoying to readers :). (It is impossible to keep people from stealing images posted on your blog or website, but hey this is better than doing nothing right?).
a) Disable right click on all images
Go to your template Edit HTML and paste the following script right after the</head>
tag.
01 | <script type= "text/javascript" > |
08 | function nocontext(e) { |
09 | var clickedTag = (e== null ) ? event.srcElement.tagName : e.target.tagName; |
10 | if (clickedTag == "IMG" ) { |
15 | var alertMsg = "Image context menu is disabled" ; |
16 | document.oncontextmenu = nocontext; |
The script will disable the context menu and replace it with this alert box:
Click on any image in this post to see it in action.
b) Disable right click on a single image
To disable context menu on a single image you need to add this piece of code (a context menu event handler) in the img tag:
oncontextmenu='alert("Image context menu is disabled");return false;'
Open the post in post editor, switch to HTML mode, locate the img tag of the image you want to disable and then insert the code inside the tag.
An example:
This is the original image tag:
< img border = "0" src = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiClMl4CETovUspyWxD1pYSsAPazPT4jsIR88ofLKpejEKnPIUjkmA1reV07kSbvBtla9fVDnwOhZyLxviWCkhDUYLJqNiAbzNIsG0lpP6v7uP2g7f0q9lg0uC6wWs65CQCRTDTCKgZ406J/s1600/2008_10260151.JPG" /> |
Once you added the context menu event handler, it should look like this:
< img oncontextmenu = 'alert("Image context menu is disabled");return false;' border = "0" src = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiClMl4CETovUspyWxD1pYSsAPazPT4jsIR88ofLKpejEKnPIUjkmA1reV07kSbvBtla9fVDnwOhZyLxviWCkhDUYLJqNiAbzNIsG0lpP6v7uP2g7f0q9lg0uC6wWs65CQCRTDTCKgZ406J/s1600/2008_10260151.JPG" /> |
Enjoy!
إرسال تعليق