回复内容: 就是简单的点击拷贝,好像很多网站都有复制代码这个按钮。但是好像说很多浏览器不支持,要用flash,现在这个问题一般都是怎么解决的
long ago都是需要引入flash通过调用flash的api访问clipboard的,巨恶心..既然现在abobe自己都不推荐flash了,自然有办法。
https://zenorocha.github.io/clipboard.js/
depende on selection and document.execcommand api
(内容测试)(你可以在这里粘帖内容)
he javascript document.execcommand('copy') support has grown, see the links below for browser updates:
ie10+ (although this document indicates some support was there from ie5.5+).
google chrome 43+ (~april 2015)
mozilla firefox 41+ (shipping ~september 2015)
opera 29+ (based on chromium 42, ~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
详见http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
