In Jquery How to handle paste?

20,018

There is an onpaste event that works in modern day browsers:

$("#textareaid").bind("paste", function(){});

Problem with the event, it tells you that it is about to happen, but it doesn't give you what the user is pasting. JavaScript has restricted acccess to the clipboard and by default it is disabled. If the access is enabled you can read the clipboard data and than manipulate it.

Share:
20,018
Njax3SmmM2x2a0Zf7Hpd
Author by

Njax3SmmM2x2a0Zf7Hpd

Updated on July 03, 2020

Comments

  • Njax3SmmM2x2a0Zf7Hpd
    Njax3SmmM2x2a0Zf7Hpd almost 4 years

    Possible Duplicates:
    How do you handle oncut, oncopy, and onpaste in jQuery?
    jQuery catch paste input

    I have a textarea, on paste to that textarea I want to

    1. format pasting values
    2. append to textarea

    could that be done in Javascript?

  • jobmo
    jobmo about 7 years
    Doesn't e.target.value give you what the user is pasting?
  • epascarello
    epascarello about 7 years
    @jobmo Well a bit has changed in the 6 years that this was answered. You get what was pasted with event.clipboardData. Reading the value will get you the entire contents of the textarea.
  • Bernhard Döbler
    Bernhard Döbler almost 6 years
    e.target.value does not necessarily contain the value. You might need setTimeout stackoverflow.com/a/1503425/577052
  • Bernhard Döbler
    Bernhard Döbler almost 6 years
    event.clipboardData does not exist in IE11