jQueryでコピー、ペースト、カットの動作を検出する方法
コピー、ペースト、カットの動作を検出するには、対応するイベントタイプをバインドするだけです。
$("#textA").bind('copy', function() { $('span').text('copy behaviour detected!') }); $("#textA").bind('paste', function() { $('span').text('paste behaviour detected!') }); $("#textA").bind('cut', function() { $('span').text('cut behaviour detected!') });
jQuery 1.4xを使用している場合は、次のような複数のイベント宣言をサポートしています:
$("#textA").bind({ copy : function(){ $('span').text('copy behaviour detected!'); }, paste : function(){ $('span').text('paste behaviour detected!'); }, cut : function(){ $('span').text('cut behaviour detected!'); } });
自分で試してみてください
<html> <head> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <style type="text/css"> span{ color:blue; } </style> </head> <body> <h1>jQuery copy, paste and cut example</h1> <form action="#"> <label>TextBox : </label> <input id="textA" type="text" size="50" value="Copy, paste or cut message here"/> </form> <span></span> <script type="text/javascript"> $(document).ready(function() { $("#textA").bind({ copy : function(){ $('span').text('copy behaviour detected!'); }, paste : function(){ $('span').text('paste behaviour detected!'); }, cut : function(){ $('span').text('cut behaviour detected!'); } }); }); </script> </body> </html>
リンク://wp-content/uploads/jQuery/jQuery-copy-paste-cut-textbox.html[デモを試してください]