为什么以下代码片段中 navigator.clipboard
总是为 undefined
?
Why is navigator.clipboard
always undefined
in the following snippet?
var clipboard = navigator.clipboard;
if (clipboard == undefined) {
console.log('clipboard is undefined');
} else {
clipboard.writeText('stuff to write').then(function() {
console.log('Copied to clipboard successfully!');
}, function() {
console.error('Unable to write to clipboard. :-(');
});
}
更多关于剪贴板API的内容可以在这里找到。
Chrome版本号:68.0.3440.106。
我确定这个曾经是可用的,但现在不行了。让人感到困惑的是,这张表格表明Chrome实现了剪贴板API(已经有一段时间了),但特定API方法的这张表格则表明API的所有方法都不支持??
clipboard
对象可用!这解释了为什么我曾经确信它之前是可以工作的。也许我应该将所有http重定向到https。谢谢...如果你提交答案,我会将其标记为正确的。 - drmrbrewer