如何在Chrome扩展程序中获取剪贴板数据? [英] How to get Clipboard data in Chrome Extension?
本文介绍了如何在Chrome扩展程序中获取剪贴板数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难找到关于如何为Ctrl + C添加侦听器,获取剪贴板数据,然后在Chrome扩展中回写到剪贴板的任何最新信息。我发现的所有旧代码都是针对旧版本的,现在已被弃用。
I'm having a hard time finding any recent info on how to add a listener for "Ctrl+C", fetching clipboard data, and then writing back to clipboard all in a Chrome Extension. All of the old code that i found was for the older versions that are now deprecated.
推荐答案
基本上,您可以使用 document.execCommand( '膏|拷贝|切')
。
Basically you can manipulate clipboard using document.execCommand('paste|copy|cut')
.
- 您需要指定
clipboardWrite
权限在清单中。 - 创建
< input>
元素(或< textarea>
) - 将焦点放在它上面 code> document.execCommand('paste')
- 从
< input>
value
属性。
- You'll need to specify
"clipboardWrite"
permissions in manifest. - Create
<input>
element (or<textarea>
) - Put focus to it
- Call
document.execCommand('paste')
- Grab you string from
<input>
value
attribute.
这有助于我将数据复制到剪贴板。
This worked for me to copy data to clipboard.
这篇关于如何在Chrome扩展程序中获取剪贴板数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文