onpaste event | paste event
Occurs before the contents of the clipboard are pasted into the document.
In Internet Explorer, the onpaste event occurs on the deepest element in the DOM hierarchy that contains the entire selection or the caret.
In Firefox, Google Chrome and Safari, the onpaste event occurs on the deepest element in the DOM hierarchy that contains the start point of the selection or the caret.
If the onpaste event is canceled, no content is inserted into the document.
- If you need access to the clipboard, use the clipboardData object in Internet Explorer.
- If you need a cross-browser solution to manipulate the contents of the clipboard, see the page for the clipboardData object.
How to register:
In HTML:
In JavaScript:
<ELEMENT onpaste="handler"> |
In JavaScript:
object.onpaste = handler; | |||||||||||
object.addEventListener ("paste", handler, useCapture); |
| ||||||||||
object.attachEvent ("onpaste", handler); |
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers.
The properties of the event object contain additional information about the current event.
To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript. |
Basic information:
Bubbles | Yes | |||||||||||||||||||
Cancelable | Yes | |||||||||||||||||||
Event object |
|
Actions that invoke the onpaste event:
- Pressing CTRL + V.
- Selecting the Paste command from the Edit menu.
- Opening the context menu (right mouse button) and selecting the Paste command.
Events related to the clipboard
Example HTML code 1:
This example illustrates the use of the onpaste event:
|
||||
<head> <script type="text/javascript"> function OnPaste () { return false; // cancels the onpaste event } </script> </head> <body> Select some text, copy it to the clipboard and try to paste it to the following fields: <br /><br /> <input type="text" size="40" value="Paste operation is enabled" /> <br /><br /> <input type="text" size="40" value="Paste operation is disabled" onpaste="return OnPaste ()" /> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
document
HTML elements:
a, abbr, acronym, address, applet, area, b, bdo, big, blockquote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, map, marquee, menu, nobr, noframes, object, ol, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments