add fallback to all copy function

This commit is contained in:
Gabriel Pastori
2023-11-30 11:59:10 -03:00
parent 2369b925f7
commit 1db00b79bd
8 changed files with 36 additions and 31 deletions

View File

@@ -0,0 +1,15 @@
export default (value) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(value);
} else {
const el = document.createElement("textarea");
el.value = value;
el.setAttribute("readonly", "");
el.style.position = "absolute";
el.style.left = "-9999px";
document.body.appendChild(el);
el.select();
document.execCommand("copy");
document.body.removeChild(el);
}
}