Why 'beforepaste' event is not fired in webkit?

dom-events, html, javascript, safari

Solution

On Chrome 23.0.1271.95 on OS X 10.8.2, `onbeforepaste` only triggers when the user causes a context menu to pop up.

http://help.dottoro.com/ljxqbxkf.php:

Occurs before the contents of the clipboard are pasted into the document and provides a possibility to enable the Paste menu item.

Right-clicking the text-box causes the `onbeforepaste` event to fire, but not pressing ctrl–v.

If it's any consolation, the `onpaste` event fires before the text is actually pasted, in my tests, so I would just use the `onpaste` event instead.

Problem

`beforecopy` event is fired, but `beforepaste` event isn't fired. Why is that? ``` <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <style type="text/css">#editor{width:300px; height:300px; border: 1px solid black;}</style> </head> <body> <div id="editor" contentEditable="true">editor</div> <script type="text/javascript"> var elEditor = document.getElementById("editor"); elEditor.addEventListener('beforecopy', function(e){ console.log('beforecopy'); e.preventDefault(); e.stopPropagation(); }); elEditor.addEventListener('copy', function(e){ console.log('copy'); }); elEditor.addEventListener('beforepaste', function(e){ console.log('beforepaste'); e.preventDefault(); e.stopPropagation(); }); elEditor.addEventListener('paste', function(e){ console.log('paste') }); </script> </body> </html> ``` - Using the Pasteboard From JavaScript - fiddle link : http://jsfiddle.net/BjR9q/

Original source