-
-
Save aslafy-z/9911ac4dc66f3eaf13009a7256ac9c79 to your computer and use it in GitHub Desktop.
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
<script> | |
// A simple function to copy a string to clipboard. See https://github.com/lgarron/clipboard.js for a full solution. | |
var copyToClipboard = (function() { | |
var _dataString = null; | |
document.addEventListener("copy", function(e){ | |
if (_dataString !== null) { | |
try { | |
e.clipboardData.setData("text/plain", _dataString); | |
e.preventDefault(); | |
} finally { | |
_dataString = null; | |
} | |
} | |
}); | |
return function(data) { | |
_dataString = data; | |
document.execCommand("copy"); | |
}; | |
})(); | |
</script> | |
<button onclick="copyToClipboard(this.textContent)">Copy me!</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment