Latest web development tutorials

onpaste event

Event Object Reference Event objects

Examples

On the <input> element in the implementation of JavaScript when pasting text:

<Input type = "text" onpaste = "myFunction ()" value = "try to paste text here">

try it"

You can see more examples at the bottom of this article.


Definition and Usage

onpaste event is triggered when the user to paste the text element.

Note: While HTML elements use support onpaste events, but in fact does not support all elements such as <p> element, unless the (See below for more examples) contenteditable as "true".

Tip: onpaste event is often used type = "text" of the <input> elements.

Tip: There are three ways you can paste the contents of elements:

  • Press CTRL + V
  • Select "Paste (Paste)" from your browser's Edit menu
  • Right-click the mouse button to select "Paste (Paste)" command in the context menu.

Browser Support

event
onpaste Yes Yes Yes Yes Yes


grammar

In HTML:

<Elementonpaste = "myScript"> try

In JavaScript:

object .onpaste = function () {myScript }; try

JavaScript, use the addEventListener () method:

object .addEventListener ( "paste", myScript ); try

Note: Internet Explorer 8 and earlier versions of IE do not support addEventListener () method.


technical details
Whether to support the bubble: Yes
It can be canceled: Yes
Event Type: ClipboardEvent
Supported HTML tags: All HTML elements


Examples

More examples

Examples

JavaScript to execute when the <p> element and paste text (note contenteditable set to "true"):

<P contenteditable = "true" onpaste = "myFunction ()"> try to paste the contents of the paragraph. </ P>

try it"


Related Pages

HTML DOM Reference: oncopy event

HTML DOM Reference: oncut event


Event Object Reference Event objects