javascript - 剪贴板通过背景页面粘贴只能工作一次
问题描述
将我的 Firefox 扩展程序转换为 Web 扩展程序并在使用 FF 60 从剪贴板粘贴时遇到问题。
我从我的后台脚本(定义它的地方)调用以下函数:
var readClipboard = function() {
let txtToPaste = document.createElement('textarea');
txtToPaste.id = "txtToPaste";
document.body.appendChild(txtToPaste);
txtToPaste.focus();
let res = document.execCommand("paste");
let result = txtToPaste.value;
txtToPaste.parentNode.removeChild(txtToPaste);
return result;
}
但是,这只适用于一次。当我单击调用此函数的按钮res
时,第一次为真,以后每次为假。
我已经尝试将 textarea 硬编码到背景 html 页面中并这样做,但没有运气。权限等必须是正确的,因为它工作一次。
编辑:我稍微更改了代码,以便它可以在 Chrome 中运行。它仍然无法在 FF 中使用。
解决方案
推荐阅读
- reactjs - React Native 错误:未定义不是对象 RNGestureHandlerModule
- python-3.x - 检查有效电子邮件地址时,模块 validate_email 会抛出 None
- php - Cloudflare 重复长请求
- javascript - 如何从 Contentful 中获取单个条目并按字段值查询?
- r - 如何在 R 中绘制矢量
- php - 如果字段存在则更新数量,如果不是 mysql php,则插入新条目
- android - 如何将嵌套的哈希表序列化/反序列化为 JSON?
- javascript - 如何计算特殊矢量符号?
- postgresql - 关于 PostgreSql JsonB 更新?
- android - 在特定时间安排日常工作