tiefen_space_h5/utils/copy.js

24 lines
745 B
JavaScript
Raw Normal View History

2024-07-02 15:09:48 +08:00
export default function copy(text = "") {
2024-08-15 21:03:10 +08:00
if (typeof window == "undefined") return;
2024-07-02 15:09:48 +08:00
let input = document.createElement("input");
input.style.position = "fixed";
input.style.top = "-10000px";
input.style.zIndex = "-999";
document.body.appendChild(input);
input.value = text;
input.focus();
input.select();
try {
2024-08-05 18:59:30 +08:00
// let result = document.execCommand("copy");
2024-07-02 15:09:48 +08:00
document.body.removeChild(input);
2024-08-05 18:59:30 +08:00
// if (!result || result === "unsuccessful") {
// // console.log("复制失败");
// } else {
// // console.log("复制成功");
// }
2024-07-02 15:09:48 +08:00
} catch (e) {
document.body.removeChild(input);
2024-08-05 18:59:30 +08:00
// console.log("当前浏览器不支持复制功能,请检查更新或更换其他浏览器操作");
2024-07-02 15:09:48 +08:00
}
}