A friend asked me to write him a cross-browser right click disabler script, so here it is! Works in all popular browsers and versions. Get it here:
<script type="text/javascript"><!--
/* http://www.3ice.hu/blog/no-right-click/ */
function a(){if(document.all){return false;}}function b(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=b;}else{document.onmouseup=b;document.oncontextmenu=a;}document.oncontextmenu=new Function("return false")
// –></script>
Right click disabler scripts will only protect you from really stupid users. Even my grandmother knows how to download the page source from the View menu, and then everything can be extracted by reading it.
This goes into the head section! Just copy it there and it will automatically work.
DEMO: compact or full versions. If you can't download from here by copy pasting, go to the demo and copy from there. (The two versions are identical, but the full is not obfuscated.)
December 5th, 2008 at 9:44 pm
Update: Added full version, which is exactly how the compact version looked before obfuscating. (So the two versions have the same functionality, but compact takes up less space and is harder to read by humans.)
I suggest getting the compact version for your website and the full version if you want to see and learn how no-right-click scripts work.