Wireless Army
This is a blog / tips and tricks website for web developers and security researchers.
follow us in feedly


disable right click on html
by admin
 at 2015-12-16 09:14:00.

want to sell some art work but scared that people with right click and save the image by right clicking? just disable the function by adding the fallowing code on to your html head tag.
<script language=JavaScript> var message="Function Disabled!"; function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") </script>
and/or disable the copy and past by adding the fallowing line to you body tag
ondragstart="return false" onselectstart="return false"
and this one will disable right click only on images but there is some way around it. It will protect you from general public but if some one really wants they can save the image.
<script language=JavaScript> var message="Function Disabled!"; function clickIE4(){ if (event.button==2){ alert(message); return false; } } function clickNS4(e){ if (document.layers||document.getElementById&&!document.all){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers){ document.captureEvents(Event.MOUSEDOWN); document.onmousedown=clickNS4; } else if (document.all&&!document.getElementById){ document.onmousedown=clickIE4; } document.oncontextmenu=new Function("alert(message);return false") </script>