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

I wanna make a extension to copy selection to clipboasd by clicking the ContextMenu.In chrome,many peo

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744870443a4598229.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信