[RESOLVED]Javascript paste from Clipboard

Hi, let assume that I copy a text (CTRL+C) somewhere out of my website.

I want using Javascript or Jquery to get paste that text in textbox…

I think you would just call this JavaScript based upon some event on the client depending on when you want to move this data from the clipboard to the textbox.

clipboardData.getdata("Text");

Hi Hamiti,

Thanks for your post.

Firstly, I agree with codeaholic, you could get the text from the clipboard by using below code.

var pastedText = window.clipboardData.getData('Text');

Secondly, the setInterval() method will wait a specified number of milliseconds, and then execute a specified function, and it will continue to execute the function, once at every given time-interval. So you could use this method to move realtime
text  from the clipboard to the textbox.

<script>
    $(document).ready(function () {        
        setInterval(function () { 
            var pastedText = window.clipboardData.getData('Text');
            $('#textA').val(pastedText);
        }, 3000);
    });
</script> 

For more information about setInterval() method, you could refer to the following link.

If you have any question about my reply, please let me know freely.

Best Regards,

Fei Han

Hamiti

let assume that I copy a text (CTRL+C) somewhere out of my website.

I want using Javascript or Jquery to get paste that text in textbox…

You can’t access user’s clipboard from javascripts. If it’s possible, then it would be a major security risk. Websites will be able to get sensitive data as copied credit card details, passwords etc. 

There are some Flash solutions which will ask permission to run on the user’s computer. Google/Bing on how to access client clipboard using Flash. It’s not possible with ASP.NET at all.

EDIT: clipboardData is only supported in IE

Leave a Reply