oncopy Event
Example
Execute a JavaScript when copying some text of an <input> element:
<input type="text" oncopy="myFunction()" value="Try to copy me">
Try it Yourself »
More examples below
Definition and Usage
The oncopy
event occurs when the user starts a copy process in the browser.
The oncopy
event occurs when the user copies element content (like a text copy).
The oncopy
event also occurs when the user copies a whole element (like an image).
3 Ways to Copy:
- Press Ctrl + C
- Select "Copy" from the Edit menu in your browser
- Right click to display the context menu, and select "Copy"
Clipboard Events
Event | Description | Bubbles |
---|---|---|
copy | The user copies content | Yes |
cut | The user starts cuts content | Yes |
paste | The user pastes content | Yes |
See Also:
Syntax
In JavaScript, using the addEventListener() method:
object.addEventListener("copy", myScript);
Try it Yourself »
Technical Details
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | ClipboardEvent |
Supported HTML tags: | All HTML elements |
More Examples
Example
Execute a JavaScript when copying some text of a <p> element:
<p oncopy="myFunction()">Try to copy this text</p>
Try it Yourself »
Example
Execute a JavaScript when copying an image:
<img src="w3schools.gif" oncopy="myFunction()">
Try it Yourself »
Browser Support
oncopy
is a DOM Level 3 (2004) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |