A user initiates copying a selection. HTML event-handler content attribute or corresponding event-handler property; the event fires only on relevant targets. The example uses document.getElementById("demo"). Event interface: ClipboardEvent. For the described native event: bubbles: yes; cancelable: yes. clipboardData can provide or replace data; normal copying should remain available. Cancel only when deliberately supplying replacement content. Example: Select text and use the ordinary copy, cut or paste command. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.

Formal Syntax & Structure

html syntaxhtml
<input oncopy="handleEvent(event)">target.addEventListener("copy", event => { /* handle event */ });

Parameters & Attributes

NameTypeDescription
oncopyJavaScript handler bodyOptional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute.
eventClipboardEventEvent object delivered to the addEventListener callback; event.type is "copy". Inspect target, currentTarget, bubbles and cancelable as appropriate.

Working Example

Example Snippethtml
<label for="demo">Sample text</label><input id="demo" value="Example text"><p role="status" id="log">Waiting for copy</p><script>  const target = document.getElementById("demo");  const log = document.getElementById("log");  target.addEventListener("copy", event => {    log.textContent = String(event.type);  });</script>

Browser Compatibility

Minimum supported versions across modern rendering engines

Widely Available
WebKit at first support; now Blink
Chrome
1
Yes
Blink
Edge
79
Yes
Gecko
Firefox
22
Yes
WebKit
Safari
3
Yes
Presto at first support; now Blink
Opera
12.1
Yes
Basic copy event is broadly interoperable; clipboard permissions and programmatic access are separate.
Clipboard API and Events
HTML Reference