0

Is it possible for jQuery to autopaste clipboard data on click a text input field? something like this:

<input type="text" name="auto" id="autoset">

And jQuery

<script>
$("#autoset").on("click",function(){
    $(this).val(getClipboardData());
});
//OR
$("#autoset").on("focus",function(){
   $(this).val(getClipboardData());
});
</script>

I mean, how do I write the getClipboardData() function.

  • $("#autoset").on("click",function(){ $(this).val(getClipboardData()); }); use this – Karthik Ganesan May 19 '17 at 15:00
  • In browsers which support it, you can use `window.clipboardData.getData('Text')`, however it will ask the user to confirm they allow the browser to access the clipboard. In browsers which do not support this, there is no way to access the clipboard in JS – Rory McCrossan May 19 '17 at 15:00

1 Answers1

0

You need to pass it as an argument in order to set value using val() method and you can combine multiple events by separating them using space.

$("#autoset").on("click focus",function(){
    $(this).val(getClipboardData());
    // or
    // this.value = getClipboardData();
});


Refer following question for getting clipboard data : Get current clipboard content?
Community
  • 1
  • 1
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188