复制/粘贴在Chrome扩展程序中不起作用 [英] Copy/Paste Not Working in Chrome Extension

查看:815
本文介绍了复制/粘贴在Chrome扩展程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

复制/粘贴代码无法在Chrome扩展程序中使用,
我需要编写Chrome扩展程序,使用剪贴板复制和粘贴数据。 代码在Backgroung.html页面中,但它不起作用。

  function buttonClick(){

document .getElementById( 'initialText')选择();


chrome.experimental.clipboard.executeCopy(1,function(){
alert(Copy);
document.getElementById('nameText')。 focus();


chrome.experimental.clipboard.executePaste(1,function(){
alert(Paste);
});
});
}


解决方案

访问是不再实验。



命令现在是 document.execCommand('paste') document.execCommand('copy') document.execCommand('cut')



然而,权限需要添加到您的清单clipboardReadclipboardWrite



尝试执行上述操作,看看您如何继续。


Following Copy/Paste code not working in Chrome Extension, I need to write Chrome Extension that copy and paste data using clipboard.

I write following code in Backgroung.html page, but its not working.

    function buttonClick(){

               document.getElementById('initialText').select();


        chrome.experimental.clipboard.executeCopy(1, function() {
            alert("Copy");
            document.getElementById('nameText').focus();


            chrome.experimental.clipboard.executePaste(1, function() {
                alert("Paste");
            });
        });
      }

解决方案

As of Chrome 13, clipboard access is no longer experimental.

The commands are now document.execCommand('paste'), document.execCommand('copy') and document.execCommand('cut').

However, permissions need to be added to your manifest: "clipboardRead" and "clipboardWrite".

Try implementing the above and see how you get on.

这篇关于复制/粘贴在Chrome扩展程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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