is simply click Copy, as if many sites have copy code this button. But it seems that many browsers do not support, to use flash, now this problem is generally how to solve
Reply content:
is simply click Copy, as if many sites have copy code this button. But it seems that many browsers do not support, to use flash, now this problem is generally how to solve
Long ago is a need to introduce flash through the call Flash API to access clipboard, the huge disgusting. Since now abobe oneself do not recommend flash, naturally have method.
https://zenorocha.github.io/clipboard.js/
Depende on Selection
and document.execCommand
API
(内容测试)(你可以在这里粘帖内容)
He JavaScript Document.execcommand (' copy ') support had grown, see the links below for browser updates:
ie10+ (although this document indicates some the there from ie5.5+).
Google Chrome 43+ (~april 2015)
Mozilla Firefox 41+ (Shipping ~september 2015)
Opera 29+ (based on Chromium, ~april 2015)
Simple Example
var copytextareabtn = Document.queryselector ('. js-textareacopybtn ');
Copytextareabtn.addeventlistener (' click ', Function (event) {
var Copytextarea = Document.queryselector ('. Js-copytextarea ');
Copytextarea.select ();
try {
var successful = document.execCommand('copy');var msg = successful ? 'successful' : 'unsuccessful';console.log('Copying text command was ' + msg);
} catch (Err) {
console.log('Oops, unable to copy');
}
});
Hello I ' m some text
Copy Textarea
See Http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript