选择整个表格/文本以复制到剪贴板
我有一个 htlm 表,其中包含大量数据,用户可能想要复制粘贴到 Excel 或其他任何内容中...
由于它很大,我想帮助用户选择它,然后他可以复制并粘贴到其中。自己贴。
我找到了这个 使用 Javascript 选择一个完整的表格(要复制到剪贴板)
,但它在 FF 中创建了一个安全错误(代码 1000),有什么想法吗?使用 jQuery 可以更有效地完成此操作吗?
I have a htlm table with lots of data the user might want to copy to paste into Excel or whatever...
Since it's big I want to help user selecting it, he can then copy & paste himself.
I found this
Select a complete table with Javascript (to be copied to clipboard)
but it creates a security error (code 1000) in FF, any thoughts? Can this be done more efficiently with jQuery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从未使用过它,但是有一个 jQuery 剪贴板插件 可以满足您的需求。听起来它会将某些内容复制到剪贴板,但应该可以跨浏览器工作。代码将类似于
编辑:我只是注意到这个解决方案需要非 IE 浏览器安装 Flash,这最多不方便,最坏的情况是无法使用。我认为在不让浏览器访问剪贴板的情况下执行此操作的唯一方法是显示一个隐藏的文本区域控件以及此调用的结果:
然后允许用户选择所有文本并复制它。它可以工作,但不如插件解决方案那么优雅。
I've never used it, but there is a jQuery clipboard plugin that could suit your needs. It sounds like it would copy something to the clipboard, but should work cross-browser. The code would be something like
Edit: I just noticed that this solution would require non-IE browsers to have Flash installed, which is inconvenient as best and makes it unusable at worst. The only way I could think to do this without having the browser access the clip board would be to display a hidden textarea control with the results of this call:
and then allow the user to select all the text and copy it. It would work, but not be as elegant as the plugin solution.