我想在 HTML5 中使用复制到剪贴板功能,但不使用 flash。可能吗?如何?
我尝试用 JavaScript 实现复制到剪贴板的功能,但它不起作用:
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');
}
}
最佳答案
您可以使用HTML5 剪贴板api
http://www.htmlgoodies.com/html5/other/working-with-clipboard-apis-in-html5-web-apps.html#fbid=eh9tM7GHJWF
但请注意,目前并非所有浏览器都完全支持它:http://caniuse.com/#feat=clipboard
关于javascript - 如何在不使用 Flash 的情况下复制到 HTML5 中的剪贴板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26336138/