为什么 document.execCommand(“paste") 在 Google Chrome 中不起作用? [英] Why is document.execCommand("paste") not working in Google Chrome?

查看:202
本文介绍了为什么 document.execCommand(“paste") 在 Google Chrome 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的扩展程序有问题.我想粘贴剪贴板中的数据.

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.

我有一种感觉,需要更改的是 document 部分,但我不知道该怎么做.有什么想法吗?

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

推荐答案

Chrome 中曾经有一个实验性的剪贴板 API,但在 Chrome 13 中被删除了.

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

Chrome 已经朝着更标准的document.execCommand('paste')document.execCommand('copy')document.execCommand('cut') 命令:https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla#Executing%5FCommands

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

在 Chrome 中,您需要将权限添加到清单中:clipboardRead"和clipboardWrite".http://developer.chrome.com/extensions/declare_permissions.html

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

在 Chrome 38 之前,这些剪贴板权限仅适用于扩展页面,例如后台脚本.从 Chrome 39 开始,在清单文件中声明剪贴板权限后,内容脚本也可以使用这些剪贴板 API (crbug.com/395376).

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

这篇关于为什么 document.execCommand(“paste") 在 Google Chrome 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆