最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to make a chrome extension to copy selection to clipboard - Stack Overflow

programmeradmin5浏览0评论

I wanna make a extension to copy selection to clipboasd by clicking the ContextMenu. In chrome,many people use a flash solusion.But how can use flash in ContextMenus.It seems impossible.Who can tell me a solusion?

What I did

var a = chrome.contextMenus.create({"title":copy,"context":["selection"],"onclick":copy});
function copy(info,tab){
document.execCommand('selectAll'); //just for example
document.execCommand('copy');
}

I have add clipboardWrite permisson to manifest.json.But it seems doesn't work. "permission":["contextMenus","clipboardWrite"]

I wanna make a extension to copy selection to clipboasd by clicking the ContextMenu. In chrome,many people use a flash solusion.But how can use flash in ContextMenus.It seems impossible.Who can tell me a solusion?

What I did

var a = chrome.contextMenus.create({"title":copy,"context":["selection"],"onclick":copy});
function copy(info,tab){
document.execCommand('selectAll'); //just for example
document.execCommand('copy');
}

I have add clipboardWrite permisson to manifest.json.But it seems doesn't work. "permission":["contextMenus","clipboardWrite"]

Share Improve this question edited Apr 3, 2012 at 5:55 user1309417 asked Apr 3, 2012 at 2:52 user1309417user1309417 411 silver badge4 bronze badges 3
  • 1 [This][1] should help. [1]: stackoverflow./questions/3436102/… – chrisjr Commented Apr 3, 2012 at 3:09
  • The Experimental Clipboard API has been removed and chrome doesn't support document.execCommand("Copy") and how can I use a flash in ContextMenus. – user1309417 Commented Apr 3, 2012 at 3:45
  • May be the experimental API is no longer experimental? code.google./chrome/extensions/manifest.html#permissions – Alejandro Silvestri Commented Apr 3, 2012 at 3:47
Add a ment  | 

2 Answers 2

Reset to default 5

Add this permission into your manifest.json:

"permissions": [ "clipboardWrite" ]

And to copy to clipboard:

document.execCommand('copy', false, null);

May be this helps. A recent addition to manifest's permissions are clipboardRead and clipboardWrite. Theese let your extension to use the method document.execCommand('copy'), for example.

http://code.google./chrome/extensions/manifest.html#permissions

发布评论

评论列表(0)

  1. 暂无评论