Skip to content

Instantly share code, notes, and snippets.

@marifuli
Last active December 25, 2021 11:54
Show Gist options
  • Save marifuli/f37a1c27963a2fa8e13aa02fa85b9c51 to your computer and use it in GitHub Desktop.
Save marifuli/f37a1c27963a2fa8e13aa02fa85b9c51 to your computer and use it in GitHub Desktop.
Copy text to clipboard
const CopyText = function() {
let t;
const e = function(e) {
t || (t = document.createElement("textarea"), document.body.appendChild(t)), t.value = e, t.setAttribute("readonly", "true"), t.setAttribute("type", "text"), t.select(), t.setSelectionRange(0, 9999);
try {
return document.execCommand("copy"), !0
} catch (t) {
return !1
} finally {
t.setAttribute("type", "hidden")
}
};
try {
module.exports = e
} catch (t) {}
return e
}();
@marifuli
Copy link
Author

It must be called directly from the user event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment