21 Mar
with a simple JavaScript function you can disable right click on you browsers. You have to do two main things
- browser detection
- mouse event detection
for it you can use below function
<SCRIPT TYPE="text/javascript"> //Disable right click java script var message="Sorry, right-click has been disabled"; function clickIE() {if (document.all) {(alert(message));return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(alert(message));return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} document.oncontextmenu=new Function("return false") </SCRIPT>
so now if you want to use in you html you can use it. Let’s create a simple dummy html to test it
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="imagetoolbar" content="no" /> <title>Rajeev Achra</title> </head> <body> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut molestie tortor ac nunc vulputate ultricies. Pellentesque blandit nulla a tortor ornare, sit amet viverra augue feugiat. Vivamus rutrum sed erat tincidunt sagittis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam interdum mauris a arcu maximus ullamcorper. Suspendisse pretium ante vitae consectetur sagittis. Nullam auctor tempus arcu sed euismod. Nam vulputate, purus commodo fringilla euismod, lacus arcu porttitor tortor, vitae placerat ante libero quis turpis. Cras aliquet orci magna, sit amet volutpat metus fermentum sed. Aliquam scelerisque nisl vel quam finibus fermentum. Aenean in turpis vel tellus ullamcorper vestibulum vel sed lectus. </body> <SCRIPT TYPE="text/javascript"> //Disable right click java script var message="Sorry, right-click has been disabled"; function clickIE() {if (document.all) {(alert(message));return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(alert(message));return false;}}} if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;} else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;} document.oncontextmenu=new Function("return false") </SCRIPT> </html>
In this html you can check by clicking right button of your mouse, it will give a message ” Sorry, right-click has been disabled”. You can modify script as you want.
I am a software engineer who specializes in Internet applications. I have worked with a wide variety of technologies and programming languages to open source LAMP environments. I have more than 6 years of object-oriented programming experience and am highly proficient in ActionScript, PHP, MYSQL, JavaScript, Jquery and a multitude of other technologies used in modern web applications.
Follow me
Latest posts by Rajeev Achra (see all)
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016