Why is document.execCommand(“paste”) not working in Google Chrome?

前端 未结 7 1741
广开言路
广开言路 2020-11-27 06:59

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

So far, I\'ve got this:

function          


        
相关标签:
7条回答
  • 2020-11-27 07:30

    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).

    0 讨论(0)
提交回复
热议问题