Monday, June 3, 2024
75
rated 0 times [  79] [ 4]  / answers: 1 / hits: 57524  / 13 Years ago, sat, august 6, 2011, 12:00:00

I have a problem with my extension. I want to paste data from the clipboard.



So far, I've got this:



function pasteAndGo()
{
document.execCommand('paste')
alert(Pasted)
}


The alert comes up, but nothing has been pasted.



I've got a feeling it's the document part that needs changing, but I don't know what to do. Any ideas?


More From » google-chrome

 Answers
16

There used to be an experimental clipboard API in Chrome, but this was removed in Chrome 13.



Chrome has moved towards the more standard document.execCommand('paste'), document.execCommand('copy') and document.execCommand('cut') commands: https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla#Executing%5FCommands



In Chrome you'll need permissions need to be added to your manifest: clipboardRead and clipboardWrite. http://developer.chrome.com/extensions/declare_permissions.html



Up until Chrome 38, these clipboard permissions were only available to extension pages such as background scripts. As of Chrome 39, content scripts can also use these clipboard APIs after declaring the clipboard permissions in the manifest file (crbug.com/395376).


[#90773] Friday, August 5, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dequant

Total Points: 88
Total Questions: 99
Total Answers: 95

Location: Ukraine
Member since Sun, Dec 13, 2020
4 Years ago
dequant questions
;