Practical Web Programming

Tuesday, October 16, 2007

No Right-Click Script

Forget long Javascript codes that disables the right-click or the context menu in your webspage. Here's a simple script that you can use to disable the right-click or the context menu in you website.

oncontextmenu="return false;

Add the Javascript codes above in the opening <body> tag of your webpage. See the example below.

<body oncontextmenu="return false;">
Put you contents here...
</body>

Take note that some browser ignores it. An example is the Opera browser, which ignores all of the no right click scripts including the no right-click script above. Likewise, it will not prevent the user from seeing your webpage's sourcecodes by using the View>Page Source or View>Source menu.

My advise is to test the script with your target users browser or with major browser around.

0 comments:

Recent Post