开发者

jQuery: detect pasting into a WYSIWYG editor

开发者 https://www.devze.com 2022-12-22 07:28 出处:网络
I\'m using htmlarea for my little CMS, and I was wondering if it\'s possible to d开发者_如何学Goetect if something gets pasted into it with jQuery?Try adding an Event Listener to your textarea for \"k

I'm using htmlarea for my little CMS, and I was wondering if it's possible to d开发者_如何学Goetect if something gets pasted into it with jQuery?


Try adding an Event Listener to your textarea for "keydown," and then looking out for keyCode == 86, that's the paste event. Now you can do whatever you want to happen when a user tries to paste.

Like this:

document.getElementById('YOURhtmlArea').addEventListener('keydown', 
function (foo)
{
     if (foo.keyCode == 86)
     {
          alert('SOMEONE IS PASTING');
          foo.preventDefault();
     }
});

I hope that helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号