This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The onpaste property returns the onPaste event handler code on the current element. See the W3C Working Draft at paste.


element.onpaste = functionRef;

where functionRef is a function - often a name of a function declared elsewhere or a function expression. See JavaScript Reference:Functions for details.


<!DOCTYPE html>
<title>onpaste event example</title>

<h1>Play with this editor!</h1>
<textarea id="editor" rows="3" cols="80">
Try pasting text into this area!

function log(txt) {
  document.getElementById("log").appendChild(document.createTextNode(txt + "\n"));
function pasteIntercept(evt) {
document.getElementById("editor").addEventListener("paste", pasteIntercept, false);

<textarea rows="15" cols="80" id="log" readonly="true"></textarea>

This example logs pastes into a textarea.


This event is sent when the user attempts to paste text.

Since Firefox 13, the preference dom.event.clipboardevents.enabled controls this feature. It defaults to true but can be disabled.


Not part of specification.


There is currently no DOM-only way to obtain the text being pasted; you'll have to use an nsIClipboard to get that information.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic support
Chrome ? Edge Full support YesFirefox Full support 3IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile Full support YesFirefox Android Full support 4Opera Android ? Safari iOS ? Samsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.

See also

Document Tags and Contributors

Last updated by: fscholz,