将文本复制到剪贴板的最佳方法是什么?(多浏览器)
我试过了:
function copyToClipboard(text) {
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData("Text", text);
} else {
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
Run Code Online (Sandbox Code Playgroud)
但在Internet Explorer中,它会出现语法错误.在Firefox中,它说unsafeWindow is not defined.
没有闪存的好技巧:Trello如何访问用户的剪贴板?
有没有人有一个脚本的例子可以在IE/Firefox中可靠地工作,以检测浏览器是否能够显示嵌入式Flash内容.我说得可靠,因为我知道它不可能100%的时间.
这个让我长期坚持下去.如何将文本复制到剪贴板?这是我的代码:
<body>
<textarea name="text" rows="5" cols="20" wrap="hard" onblur="CopyToClipboard()">Enter text here and it will be copied to the clipboard!</textarea>
</body>
<script type="text/javascript">
function CopyToClipboard() {
//O_O Confused... what do I do...
}
</script>
Run Code Online (Sandbox Code Playgroud)