2

I have an ASP.NET web application. I would like to get Text that is on the client's clipboard currently and paste in the textbox on my web page. Is there a way to do that?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Denis
  • 11,796
  • 16
  • 88
  • 150
  • What does your code look like..? have you tried looking up `GetText` method of the Clipboard...? `Clipboard.GetText` – MethodMan May 29 '13 at 17:53
  • 2
    @DJ Craze: that will get the clipboard from the server, not the client. – Denis May 29 '13 at 17:56
  • Doesn't look easy. http://stackoverflow.com/questions/3475293/copy-and-paste-clipboard-in-javascript-or-jquery – gwin003 May 29 '13 at 18:34
  • 2
    This seems like a security nightmare waiting to happen...What if somebody has something confidential in their clipboard? – KingCronus May 29 '13 at 20:57
  • @KingCronus, yeah figured this is why it was that hard but thought someone might have a solution for this. – Denis Jun 03 '13 at 20:07

2 Answers2

1

Copying clipboard content through Javascript is dangerous and highly vulnerable approach. If you still want to implement client-side copy then you should checkout ZeroClipboard.

https://github.com/jonrohan/ZeroClipboard

Firoz Ansari
  • 2,505
  • 1
  • 23
  • 36
0

All security freaks(of which I am one) seem to forget that there are web deployments to the intranet... and in this case, if you care that it only works in IE (and Firefox with an extension) you can use this guide.

To paste, with a bit of jQuery thrown-in for flavor :)

    $('.pasteHotspot').on('click', function (e) {
         e.preventDefault();

         var pasteField = $(this).parent().find('.pasteField')[0];

         // Keeps the other browsers from throwing exceptions..
         if (typeof pasteField.createTextRange != 'function') return;

         paste(pasteField);
     }


     function paste(pasteField) {
         pasteField.focus();

         pasteField.select();

         var therange = pasteField.createTextRange();

         therange.execCommand("Paste");
     }
Serj Sagan
  • 28,927
  • 17
  • 154
  • 183