Created
May 5, 2020 06:16
-
-
Save shibbirweb/153e609fdbd9ee103600e58bf6c7da00 to your computer and use it in GitHub Desktop.
Copy a input field by on click
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
| let referCode = document.getElementById('refer_code'); | |
| referCode.select() | |
| try { | |
| const successful = document.execCommand('copy'); | |
| const msg = successful ? 'successful' : 'unsuccessful'; | |
| alert('Refer code was copied ' + msg); | |
| } catch (err) { | |
| alert('Oops, unable to copy'); | |
| } | |
| /* unselect the range */ | |
| window.getSelection().removeAllRanges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment