0

I'm using htmlarea for my little CMS, and I was wondering if it's possible to detect if something gets pasted into it with jQuery?

1

1 Answer 1

1

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.

2
  • 1
    What happens if they use the mouse to paste text into the area?
    – orandov
    Mar 3, 2010 at 23:50
  • 1
    Not sure how, but ckEditor handles this. You could start tearing apart their code, it is open source. Mar 4, 2010 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.