Skip to content

Instantly share code, notes, and snippets.

@lzl124631x
Created September 27, 2022 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lzl124631x/4bc8ac6a58ab460ece62212d2cf32b2f to your computer and use it in GitHub Desktop.
Save lzl124631x/4bc8ac6a58ab460ece62212d2cf32b2f to your computer and use it in GitHub Desktop.
Copy String
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