oncopy event
Example
Execute JavaScript when text is copied on the element: element when text is copied to execute JavaScript:
Try it »
More examples are included at the bottom of this article.
Definition and Usage
The oncopy event is triggered when the user copies the content on an element.
Tip: The oncopy event is also triggered when the user copies an element, for example, copying .
Tip: The oncopy event is usually used for type="text" .
Tip: There are three ways to copy elements and content:
- Press CTRL + C
- Select "Copy" in the Edit menu of your browser
- Right-click the mouse button and select the "Copy" command in the context menu.
Browser support
| Events | |||||
|---|---|---|---|---|---|
| oncopy | Yes | Yes | Yes | Yes | Yes |
Note: When trying to copy an image (see more examples), the oncopy event may not work in Chrome, Firefox and Opera browsers.
Syntax
In HTML:
<
element
oncopy="
myScript
">Try it
In JavaScript:
object
.oncopy=function(){
myScript
};
Try it
In JavaScript, use the addEventListener() method:
object
.addEventListener("copy",
myScript
);
Try it
Note: Internet Explorer 8 and earlier IE versions do not support addEventListener() method.
Technical Details
| Does it support bubbling: | Yes |
|---|---|
| Is it cancelable: | Yes |
| Event type: | ClipboardEvent |
| Supported HTML tags: | All HTML elements |
More examples
Example
Execute JavaScript when copying the text content of the element:
the text content of the element to execute JavaScript:
Try to copy the text
Try it »
Example
Execute JavaScript when copying an image:
Try it »
Related pages
HTML DOM Reference Manual: onpaste event
HTML DOM Reference Manual: oncut event
Event Object