dom / latest / document / paste_event.html /

Document: paste event

The paste event fires when the user initiates a paste action through the browser's user interface.

The original target for this event is the Element that was the intended target of the paste 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: paste event.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener('paste', event => { });

onpaste = event => { };

Event type

Examples

To be informed when a user pastes data to the webpage from their clipboard, you can add a handler to your Document instance using addEventListener(), like this:

document.addEventListener("paste", function(event) {
  /* the session has shut down */
});

Alternatively, you can use the Document.onpaste event handler property to establish a handler for the paste event:

document.onpaste = function(event) {
 /* the session has shut down */
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
paste_event
1
17
12
The onpaste event handler property is not supported.
6
9
The onpaste event handler property is not supported.
≤12.1
2
1
18
6
≤12.1
1
1.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Document/paste_event