Created
January 14, 2022 08:46
-
-
Save mahammad/809ecf693e0c657fc0f4454470c1d221 to your computer and use it in GitHub Desktop.
how to copy content to clipboard in javascript
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 contentCopy(input,title){ | |
var r = document.createRange(); | |
r.selectNode(document.getElementById(input)); | |
window.getSelection().removeAllRanges(); | |
window.getSelection().addRange(r); | |
document.execCommand('copy'); | |
window.getSelection().removeAllRanges(); | |
toastr['success']( '@lang("Copied to clipboard!")',title); // optional bonus | |
} | |
$(document.body).on('click', '.js-copy-shortcut', function() { | |
contentCopy($(this).data('id'), $(this).data('value')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment