先是参考了:https://blog.51cto.com/u_16213428/9299868,可惜无效!!!主要api打印出来是undefined
一顿好找:https://segmentfault.com/q/1010000043550405,有效!!!
主要代码:
setTimeout( async () => {
try {
const clipboardItems = await navigator.clipboard.read();
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
const blob = await clipboardItem.getType(type);
console.log("已读取剪贴板中的内容:", await blob.text());
}
}
} catch (err) {
console.error("读取剪贴板内容失败: ", err);
}
}, 1000)