与页面复制粘贴有关的方法
2022-04-12 本文已影响0人
townYouth
// 获取裁剪版内容
const getClipboard = async function () {
const value = await navigator.clipboard.readText()
return value
}
// 获取页面选中的文字
const getSelectText = function () {
return window.getSelection().toString()
}
// 设置粘贴内容
const setClipboard = async function (value = ' ') {
const text = document.createElement('textarea');
text.value = value;
document.body.appendChild(text);
text.select();
document.execCommand('Copy');
text.remove();
}