Last active
December 25, 2021 11:54
-
-
Save marifuli/f37a1c27963a2fa8e13aa02fa85b9c51 to your computer and use it in GitHub Desktop.
Copy text to clipboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It must be called directly from the user event.