How to disable right click on any HTML or PHP webpage.
You may want to protect your webpages from visitors viewing the source code using “right click – view source”. There is a simple bit of script that you can paste on any HTML or PHP page that will disable the right click ability. I use this to protect many of my webpages that have sensitive data within the source code. It is not 100% reliable but will block most visitors from accessing the source code. Obviously some web developers will have their workarounds, however, I have not had a problem so far with this code from dynamicdrive.com.
At dynamicdrive.com you will find all kinds of tools that you can use for free. I hope that you pay their website a visit because they deserve all the credit for helping many web developers with coding and they do it for free.
Ok now lets disable right clicking on your webpages using the simple code below. Just paste it at the bottom of your HTML or PHP page.
Where it says “var message=””; you can add a message that will appear when your website visitors right click the page. This message function will only work in some older browsers and IE.
Also note that most modern browsers, such as Chrome, have a “view source” function built into the menu bar under the “Developer” section as seen below:
It is not perfect but can be used to hide your source code from the normal website visitor with little knowledge of how things work in the developer world.