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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With