Document: copy event
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
The copy
event fires when the user initiates a copy action through the browser's user interface.
The original target for this event is the Element
that was the intended target of the copy action. You can listen for this event on the Document
interface to handle it in the capture or bubbling phases. For full details on this event please see the page on the Element: copy event.
Syntax
Use the event name in methods like addEventListener()
, or set an event handler property.
addEventListener("copy", (event) => {});
oncopy = (event) => {};
Event type
A ClipboardEvent
. Inherits from Event
.
Examples
To be informed when a user copies data from the webpage to their clipboard, you can add a handler to your Document
instance using addEventListener()
, like this:
document.addEventListener("copy", (event) => {
/* the session has shut down */
});
Alternatively, you can use the Document.oncopy
event handler property to establish a handler for the copy
event:
document.oncopy = (event) => {
/* the session has shut down */
};
Specifications
Specification |
---|
Clipboard API and events # clipboard-event-copy |
HTML Standard # handler-oncopy |
Browser compatibility
BCD tables only load in the browser