目录

oncopy Event

Example

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


Description

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 Occurs When
copy The user copies content
cut The user starts cuts content
paste The user pastes content

See Also:

The Cliboard Event Object


Syntax

In HTML:

< element oncopy=" myScript">
Try it Yourself »

In JavaScript:

object.oncopy = function(){ myScript};
Try it Yourself »

In JavaScript, using the addEventListener() method:

object.addEventListener("copy", myScript);
Try it Yourself »

Technical Details

Bubbles: Yes
Cancelable: Yes
Event type: ClipboardEvent
HTML tags: All HTML elements


More Examples

Example

Call a function when copying some text of a <p> element:

<p oncopy="myFunction()">Try to copy this text</p>
Try it Yourself »

Example

Call a function when copying an image:

<img src="91xjr.gif" oncopy="myFunction()">
Try it Yourself »

Browser Support

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