Created
January 30, 2019 06:26
-
-
Save SarathSantoshDamaraju/6ae61d273ec4a8432949077b374b793e to your computer and use it in GitHub Desktop.
Copy function value to clipboard with Pure JS
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
/* ==== | |
ClipboardCopy: This accepts any given string and copys it into clipboard after desired operation. | |
==== */ | |
function ClipboardCopy(str){ | |
/* Some login */ | |
str = str.toLowerCase(); | |
let convertedStr = str.split(" ").join("-"); | |
/* Copy code */ | |
let $tempInput = document.createElement('INPUT'); | |
document.body.appendChild($tempInput); | |
$tempInput.setAttribute('value', convertedStr) | |
$tempInput.select(); | |
document.execCommand('copy'); | |
document.body.removeChild($tempInput); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment