如何阅读谷歌Chrome扩展中的剪贴板文本 [英] How to read the Clipboard text in google chrome extension

查看:385
本文介绍了如何阅读谷歌Chrome扩展中的剪贴板文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试阅读Google Chrome扩展程序中的剪贴板文本。到目前为止,我已经尝试过使用这些代码,并且它返回给我的是未定义的。请帮助我。

在background.html中,我的代码是

  chrome.extension。 onRequest.addListener(function(request,sender,sendResponse){
if(request.method ==getClipData)
sendResponse({data:document.execCommand('paste')});
else
sendResponse({}); //对它们进行缓存
});

在我的内容脚本中,我的代码是

<$ (方法:getClipData},函数(响应){
alert(response.data);
}); pre> chrome.extension.sendRequest


解决方案

曾几何时,有一个实验性的API chrome。 experimental.clipboard,但不再有 http://code.google .com / chrome / extensions / trunk / experimental.clipboard.html



也许你应该试试:如何复制到剪贴板的JavaScript?



更新:
我错了 - 有可能。正如权限页面所示,存在剪贴板读取和剪贴板写入权限。所以也许他们会为你工作。


I am trying to read clipboard text in Google chrome extension. As of now I have tried with tis code and it is returning me undefined. Please help me on this.

In background.html my code is

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
 if (request.method == "getClipData")
   sendResponse({data: document.execCommand('paste')});
 else
   sendResponse({}); // snub them.
 });

In My content script my code is

chrome.extension.sendRequest({method: "getClipData"}, function(response) {
   alert(response.data);
});

解决方案

Once upon a time there was an experimental API chrome.experimental.clipboard, but there is no more http://code.google.com/chrome/extensions/trunk/experimental.clipboard.html

Maybe you should try: How do I copy to the clipboard in JavaScript?

UPDATE: I was wrong - there is a possibility. As permissions page says there are "clipboardRead" and "clipboardWrite" permissions. So maybe they will work for you.

这篇关于如何阅读谷歌Chrome扩展中的剪贴板文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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