Execute a JavaScript when copying some text of an <input> element:
<!DOCTYPE html> <html> <body> <input type="text" oncopy="myFunction()" value="Try to copy this text"> <p id="demo"></p> <script> function myFunction() {//from w w w. j av a 2 s . c om document.getElementById("demo").innerHTML = "You copied text!" } </script> </body> </html>
The oncopy event occurs when the user copies the content of an element.
The oncopy event occurs when the user copies an element, for example, an image, created with the <img> element.
The oncopy event is mostly used on <input> elements with type="text".
The oncopy event may not work when trying to copy an image.
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | ClipboardEvent |
Supported HTML tags: | All HTML elements |