Created
September 27, 2022 18:07
-
-
Save lzl124631x/4bc8ac6a58ab460ece62212d2cf32b2f to your computer and use it in GitHub Desktop.
Copy String
This file contains 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
function copy(str) { | |
// Chrome Console API is not available :( Have to use this way. | |
const el = document.createElement("textarea"); | |
el.value = str; | |
el.setAttribute("readonly", ""); | |
el.style.position = "absolute"; | |
el.style.left = "-9999px"; | |
document.body.appendChild(el); | |
el.select(); | |
document.execCommand("copy"); | |
document.body.removeChild(el); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment