5

Possible Duplicate:
Detect pasted text with ctrl+v or right click -> paste

I'm coding a js editor now. I want to do something (detect pasted text, etc.) just after the paste.

Community
  • 1
  • 1
lovespring
  • 19,051
  • 42
  • 103
  • 153

1 Answers1

2

Here's an example of handling paste event:

http://www.quirksmode.org/dom/events/tests/cutcopypaste.html

It's supported on many browsers but not 100% - see this table for compatibility: http://www.quirksmode.org/dom/events/cutcopypaste.html

You can also work around not having a paste event on some browsers by:

  • Remembering full contents of the form field at some time

  • Setting a timeout event

  • On timeout, take the contents of the field again, compare to the previous contents, and detect changes. Lather, rinse, repeat

DVK
  • 126,886
  • 32
  • 213
  • 327
  • It is possible to "paste" the exact same text into a field, and to still want to do something special if the user tries that – Joel Coehoorn Dec 26 '10 at 02:16
  • @Joel - OK, I give up. What would be the purpose of doing something like that? Short of "You pasted unchanged text" warning, I can't come up with anything useful. – DVK Dec 26 '10 at 02:43
  • 2
    Maybe you transform the text after pasting, and so it won't stay the same? It doesn't matter why - it could happen. Anyway, I upvoted the answer, I just wanted to make sure anyone later on was aware of the caveat. – Joel Coehoorn Dec 26 '10 at 04:11