I have an input box where I'm setting the value using jQuery's val()
method. I would like to copy to clipboard after setting the value in this textbox. I'm using document.execCommand('copy')
but that doesn't seem to work when there is no user action. Is there a different way of solving this?
I set the value in this text after making an AJAX call to the server to fetch a value. Here's what I'm trying to do.
$('#someVal').val('Some text');
el = $('#someVal');
el.focus();
el.select();
document.execCommand("copy", true);