How to prevent users right clicking on images

The ability to disable the web browser contextual menu or 'right click' function isn't built into Pixaria but it's quite easy to add it yourself. To implement this feature, put the code snippet below into your current theme's HTML header template file before the </head> tag.

For help with themes and template files, please see the documentation pages on templates and customisation.

N.B. This trick won't stop users of some newer browsers such as Firefox and Safari from simply dragging and dropping images off your site. Use the Adobe Flash output feature for more security.


<script language=JavaScript>
<!--

///////////////////////////////////
function clickIE4(){
if (event.button==2){
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
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("return false")

// -->
</script>

Go back to contents

Created: Wednesday, August 22, 2007
Last edited: Wednesday, August 22, 2007


image Pixaria Gallery Divestock