为什么document.execCommand('paste')在我的扩展中不起作用 [英] Why document.execCommand('paste') is not working in my extension

查看:1174
本文介绍了为什么document.execCommand('paste')在我的扩展中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个可以读取剪贴板内容的Google Chrome扩展程序。

但我无法获取此文档。我想在IE的剪贴板API中获取剪贴板内容。

在清单文件中,我给了

的许可权

  clipboardRead和clipboardWrite。 

我在Background页面中创建了一个函数,如下所示:

  chrome.extension.onRequest.addListener(function(request,sender,sendResponse){
if(request.method ==getClipData)
sendResponse ({data:document.execCommand('paste')});
else
sendResponse({}); //删除它们
});

在Content Script中,我调用这个函数

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

但是,这会返回我未定义的状态...

解决方案

var str = document.execCommand('paste');

您需要添加 clipboardRead < href =https://code.google.com/chrome/extensions/manifest.html#permissions =nofollow>权限。


I am creating a Google chrome extension which can read the contents of clipboard.
But I am unable to get the documentation for this. I want to get the clipboard content as in IE's clipboard API.
In the manifest file i gave permissions to

clipboardRead and clipboardWrite.  

I have created a function in Background page as below

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

And in Content Script I am calling the function like this

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

But this returns me undefined...

解决方案

var str = document.execCommand('paste');

You will need to add the clipboardRead permission too.

这篇关于为什么document.execCommand('paste')在我的扩展中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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