如何在不使用flash的情况下将div的内容复制到剪贴板 [英] How to copy a div's content to clipboard without flash
问题描述
就是这样:)我有一个ID为 #toCopy 的div和一个ID为 #copy 的按钮。
当按 #copy 时,将 #toCopy 内容复制到剪贴板的最佳方式是什么? 解决方案
UPDATED ANSWER
在使用剪贴板时,JavaScript受到了限制。
,但现在它支持复制/粘贴命令。
查看mozilla和caniuse.com的文档。
document.execCommand('paste')
确保您支持不支持的浏览器。
https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand
http://caniuse.com/#search=command
JavaScript不允许使用剪贴板,但其他插件像闪光灯有访问权限。
That's it :) I have a div with the id #toCopy, and a button with the id #copy. What's the best way to copy #toCopy content to clipboard when pressing #copy?
UPDATED ANSWER Javascript was restricted from using the clipboard, early on. but nowadays it supports copy/paste commands. See documentation of mozilla and caniuse.com.
document.execCommand('paste')
make sure that you support browsers that don't.
https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand http://caniuse.com/#search=command
Javascript is not allowed to use the clipboard, but other plugins like flash do have access.
How do I copy to the clipboard in JavaScript?
这篇关于如何在不使用flash的情况下将div的内容复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!