Tuesday, March 8, 2011

How to disable right click on Blogger image


1. Log in to blogger and Go to Design >> Page Element

2. Click  'Add a Gadget' and select 'HTML/Javascript'

3.Paste below code.

<script language="JavaScript1.2">

var clickmessage="Right click disabled on images!"

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()
</script>

4. Now click save you are done.

2 comments:

  1. Tried this on http://gmac99.blogspot.com/
    Alert message does pop up but when you click to leave the pop up the standard right click options pop up and I can do whatever.
    Any thoughts?
    Tnx/G

    ReplyDelete
  2. it works only trouble is if they click normaly then right click they can still save is there away around this part please. thank you for the code as it has helped

    ReplyDelete