In this article, we will learn how to prevent the user from copying content using JavaScript.
If in an HTML page, the user should not be allowed to copy a text. You can use JavaScript for this.
<!DOCTYPE html> <html> <body> <h1 oncopy="return false;">TheCodeHubs</h1> <p>Enter Any Value: </p> <input oncopy="return false;" oncut="return false;" /> </body> </html>
Here, on <h1> element we applied oncopy attribute. Where, on <input> element we applied oncopy and oncut attributes because <input> element provides both copy and cut options.
In the above example, we applied oncopy attribute on separate elements. We can also apply it on <body> element as shown below.
<!DOCTYPE html> <html> <body oncopy="return false;" oncut="return false;"> <h1>TheCodeHubs</h1> <p>Enter Any Value: </p> <input /> </body> </html>
That’s it.
Output:
Also, check How To Prevent Copy Content Using CSS