我想从我创建一个Chrome扩展到剪切板写一些数据。 在manifest文件中我给的权限都clipboardRead和clipboardWrite。为什么document.execCommand(“copy”)在我的Chrome扩展的内容脚本中不起作用?
我使用这个功能,我发现here
,但它不工作。似乎“document.execCommand('copy');”无法工作。
我写这些代码的内容脚本。
THX 清单:
{
"manifest_version":2,
"name":"easyCopy",
"description":"just a small toll",
"version":"1.0.0",
"permissions":[
"clipboardWrite", "http://*/*", "clipboardRead"
],
"content_scripts":[
{
"matches":["http://*/*"],
"js":["jquery-1.9.1.min.js", "main_feature.js"]
}
],
"background":{
"persistent":false,
"page":"background.html"
}
}
main_feature.js:
copyOrderId();
function copyOrderId() {
$(".order-num").click(function() {
var curOrderNum = $(this).text();
copyTextToClipboard(curOrderNum);
// chrome.extension.sendMessage({method:"copy", content:curOrderNum}, function (response) {
// clog(response);
// });
});
}
function copyTextToClipboard(text) {
var copyFrom = $('<textarea/>');
copyFrom.text(text);
$('body').append(copyFrom);
copyFrom.select();
document.execCommand('copy', true);
copyFrom.remove();
}
function clog(message) {
console.log(message);
}
的background.html仅仅是基本的HTML身体一个空白页。
分享您完整的相关代码,包括清单等 – Sudarshan 2013-02-22 09:14:32
THX,我编辑我的问题,并分享他们都 – 2013-02-22 10:14:58