I want to use a copy-to-clipboard function in HTML5, but without using flash. Is it possible? How?
I tried to implement a copy-to-clipboad function with JavaScript, but it is not working:
function Copytoclipboard() {
var body = document.body,
range, sel;
if (document.createRange && window.getSelection) {
range = document.createRange();
sel = window.getSelection();
sel.removeAllRanges();
try {
range.selectNodeContents(el);
sel.addRange(range);
document.execCommand('Copy');
} catch (e) {
range.selectNode(el);
sel.addRange(range);
document.execCommand('Copy');
}
} else if (body.createTextRange) {
range = body.createTextRange();
range.moveToElementText(el);
range.select();
range.execCommand('Copy');
}
}
question from:
https://stackoverflow.com/questions/26336138/how-can-i-copy-to-clipboard-in-html5-without-using-flash 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…