Just for educational purposes - disabling right click on all images in IE5+/Gecko using a different method:
Use this CSS:
img {
behavior: url(disablecontext.htc);
-moz-binding: url(disablecontext.xml#dis);
}
And save this as disablecontext.htc:
Code:
<PUBLIC:ATTACH event="oncontextmenu" onevent="disableIt()"/>
<script type="text/javascript">
function disableIt() {
event.returnValue = false;
event.cancelBubble = true;
alert('Right click on images disabled');
return false;
}
</script>
And this as disablecontext.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://www.mozilla.org/xbl">
<binding id="dis">
<handlers>
<handler event="contextmenu" phase="capturing">
event.stopPropagation();
event.preventDefault();
alert('Right click on images disabled');
return false;
</handler>
</handlers>
</binding>
</bindings>
Not that it'll do you any good, but at least this provides an interesting perspective on behaviors and bindings.
Note: Since the disabling of right click on images is done through CSS, this also includes any img's dynamically added to the document after page load, without relying on document-level events such as onmousedown. Which means other scripts can still make use of those events... preventing conflicts.