4

beforecopyイベントは発生しますが、beforepasteイベントは発生しません。何故ですか?

<!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>
4

1 に答える 1

8

OS X10.8.2のChrome23.0.1271.95ではonbeforepaste、ユーザーがコンテキストメニューをポップアップさせたときにのみトリガーされます。

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

クリップボードの内容がドキュメントに貼り付けられる前に発生し、[貼り付け]メニュー項目を有効にする可能性を提供します。

テキストボックスを右クリックすると、イベントが発生しますが、 –<kbd>vonbeforepasteは押されません。ctrl

それが慰めであるonpaste場合、私のテストでは、テキストが実際に貼り付けられる前にイベントが発生するので、onpaste代わりにイベントを使用します。

于 2012-12-07T03:42:32.087 に答える