如何在不使用flash的情况下将div的内容复制到剪贴板 [英] How to copy a div's content to clipboard without flash

查看:121
本文介绍了如何在不使用flash的情况下将div的内容复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就是这样:)我有一个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不允许使用剪贴板,但其他插件像闪光灯有访问权限。



如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆