Execute a JavaScript when copying some text of an <input> element:
More "Try it Yourself" examples below.
The oncopy event occurs when the user copies the content of an element.
Tip: The oncopy event also occurs when the user copies an element, for example, an image, created with the <img> element.
Tip: The oncopy event is mostly used on <input> elements with type="text".
Tip: There are three ways to copy an element/the content of an element:
Event | |||||
---|---|---|---|---|---|
oncopy | Yes | Yes | Yes | Yes | Yes |
Note: The oncopy event may not work as expected in some browsers when trying to copy an image (See "More Examples" below).
In HTML:
In JavaScript:
In JavaScript, using the addEventListener() method:
Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | ClipboardEvent |
Supported HTML tags: | All HTML elements |
Execute a JavaScript when copying some text of a <p> element:
Execute a JavaScript when copying an image:
HTML DOM reference: onpaste event
HTML DOM reference: oncut event