Denis
Denis

Reputation: 12077

Paste Text currently on clipboard in ASP.NET

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?

Upvotes: 2

Views: 2639

Answers (2)

Serj Sagan
Serj Sagan

Reputation: 30208

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");
     }

Upvotes: 0

Firoz Ansari
Firoz Ansari

Reputation: 2515

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

Upvotes: 1

Related Questions