(Tested using Chrome 44)
Desired behavior . Make an XHR request, put the result in the text area, select the text and copy to the clipboard.
Actual behavior . On a successful request, XHR places the result in the text area and selects it, but does not copy the result to the clipboard. But if I initiate a copy outside the XHR callback, it works.
Example html page:
var selectAndCopy = function() {
<html> <head> </head> <body> <p> <textarea id="textarea">Hello, I'm some text!</textarea> </p> <p> <button id="fetch_copy">Fetch Data and Copy Textarea</button> <button id="copy">Copy Textarea</button> </p> </body> </html>
If you click the "Get data and copy text area" button, the data will be successfully extracted, but not copied. If you click the Copy Text Area button, the text will be copied as expected. I tried many query / copy combinations to try to get it to work, but to no avail (including programmatically pressing the copy button after data extraction). Does anyone know what is going on here? Is it a security feature or something else?
I do not want the user to have to press two buttons to extract and copy, if possible.
javascript html ajax copy execcommand
aeoliant
source share