Run command Ctrl + V "paste" with mouse click inside an input

2

Hello friends is it possible with a mouse click to execute the command Ctrl + v "paste" into an input with jquery?

I already have a script that copies everything inside the input. now I need another one that when I click on another input paste the copied text.

I managed to make it work in IE but not in Chrome


function paste() {
    document.execCommand('paste')
}


    
asked by anonymous 28.09.2016 / 02:27

4 answers

2

Have you tried using the command below?

document.execCommand('paste');

Here is a list of all available commands: link

    
28.09.2016 / 06:06
0

Okay, I used it like that on my site.

<script type="text/javascript">
    var copyTextareaBtn = document.querySelector('.textarea');

    copyTextareaBtn.addEventListener('click', function(event) {
      var copyTextarea = document.querySelector('.textarea');
      copyTextarea.select();

      try {
        var successful = document.execCommand('copy');
        var msg = successful ? 'sim!' : 'não!';
      } catch (err) {

      }
    });
 </script>



    <textarea class="textarea"  rows="4" cols="25"  onClick="this.setSelectionRange(0, this.value.length)" >
        <a  target="_blank" href="http://www.adota-me.tk">
            <img border="0" alt="adota-me.tk"  src="https://scontent-mad1-1.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/12688280_1755291221366035_3011947917400908476_n.jpg?oh=894ed3c1dc9994d4ab489aab424844ff&oe=575423D6"width="150" height="100">
        </a>
    </textarea>
    
28.09.2016 / 03:10
0

This should work:

function paste() {
    document.execCommand('paste')
}

$(function(){
    $('input[type="text"]').focus(function(){
        paste();
    });
});
    
05.10.2016 / 22:14
-1

You need a click method to call the CRTL V.

For example:

$("p").click(function(){
//aqui faz a função});

Search the jQuery .keypress in this documentation here.

This jQuery forum here can also help.

A hug.

    
28.09.2016 / 02:58