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

EventOccurs When
copyThe user copies content
cutThe user starts cuts content
pasteThe 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="w3schools.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


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.