Call a function when copying some text of an <input> element:
<input type="text" oncopy="myFunction()" value="Try to copy me">
Try it Yourself »
More examples below
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).
Event | Occurs When |
---|---|
copy | The user copies content |
cut | The user starts cuts content |
paste | The user pastes content |
In JavaScript, using the addEventListener() method:
object.addEventListener("copy",
myScript);
Try it Yourself »
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | ClipboardEvent |
HTML tags: | All HTML elements |
Call a function when copying some text of a <p> element:
<p oncopy="myFunction()">Try to copy this text</p>
Try it Yourself »
Call a function when copying an image:
<img src="91xjr.gif" oncopy="myFunction()">
Try it Yourself »
oncopy
is a DOM Level 3 (2004) feature.
It is fully supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!