21 Mar
Sometime you need to prevent you text from simple copy paste. For it you can disable text selection on your browser. By this article i am just giving an example to handle browser event. It’s a tricky method not full proofed method to prevent your text from copy-paste.
You can use a JavaScript function as below
<SCRIPT TYPE="text/javascript"> //Disable select-text script (IE4+, NS6+) function disableselect(e){ return false } function reEnable(){ return true } //if IE4+ document.onselectstart=new Function ("return false") //if NS6 if (window.sidebar){ document.onmousedown=disableselect document.onclick=reEnable } </SCRIPT>
Also you can use a example or test html like
<!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 select-text script (IE4+, NS6+) function disableselect(e){ return false } function reEnable(){ return true } //if IE4+ document.onselectstart=new Function ("return false") //if NS6 if (window.sidebar){ document.onmousedown=disableselect document.onclick=reEnable } </SCRIPT> </html>
By running this html on your browser you can check. It’s not allowing you to select your text. But user still can get your data from source of html or by right clicking with option select all.
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