onbeforepaste event | beforepaste event
Occurs before the contents of the clipboard are pasted into the document and provides a possibility to enable the Paste menu item.
The onbeforepaste event is useful if you want to enable the Paste menu item for a non-editable element (textarea, input:text, input:file and input:password) in a non-editable region (see the contentEditable and designMode properties).
To enable the Paste menu item for an element, return false from an event handler for the onbeforepaste event on it.
If you want to implement the functionality of the Paste operation in Google Chrome and Safari, see the page for the clipboardData object.
It contains a cross-browser example that shows how to access the clipboard.
To remove the contents of the selection from the document, use the deleteFromDocument method.
- In Internet Explorer, the onbeforepaste event occurs on the deepest element in the DOM hierarchy that contains the entire selection or the caret.
- In Google Chrome and Safari, the onbeforepaste event occurs on the deepest element in the DOM hierarchy that contains the start point of the selection or the caret.
How to register:
In HTML:
In JavaScript:
<ELEMENT onbeforepaste="handler"> |
In JavaScript:
object.onbeforepaste = handler; | |||||||||||
object.addEventListener ("beforepaste", handler, useCapture); |
| ||||||||||
object.attachEvent ("onbeforepaste", 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 onbeforepaste event:
- Pressing CTRL + V.
- Opening the Edit menu.
- Opening the context menu (right mouse click).
Events related to the clipboard:
Example HTML code 1:
This example shows how to enable the Paste menu item for a non-editable content:
|
||||
<head> <script type="text/javascript"> function EnablePaste () { return false; // enable the Paste menu item } function OnPaste () { if (window.clipboardData) { window.clipboardData.setData ("Text", "My clipboard data"); } } </script> </head> <body> <div onbeforepaste="return EnablePaste ()" onpaste="OnPaste ()"> Select some text on this page and use the Paste menu item in the Edit menu or in the context menu (right mouse click) to paste the 'My clipboard data' text into the document. In Google Chrome and Safari, no content will be pasted. </div> </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