What I am doing is programmatically select all text from a webpage and then copy it. The select all works with execCommand
but copy doesn't.
Here is my code:
$.ajax({
url: $('#url').val(),
type: 'GET',
success: function(res) {
$('#result').html(res.responseText);
$('#result').fadeIn('fast');
$('#result').focus();
$('#result').select();
document.execCommand('selectall');
// copy does not work ?
document.execCommand('copy');
}
});
Here is Example on JsBin
I also tried using flash solution such as ZeroClipboard, however it seems that one has to press their flash object/button explicitly to copy text whereas I wanted to do zeroclip.setText('whatever');
without user's pressing the button.
Can anyone tell how to copy text programmatically?