Skip to content

Instantly share code, notes, and snippets.

@mahammad
Created January 14, 2022 08:46
Show Gist options
  • Save mahammad/809ecf693e0c657fc0f4454470c1d221 to your computer and use it in GitHub Desktop.
Save mahammad/809ecf693e0c657fc0f4454470c1d221 to your computer and use it in GitHub Desktop.
how to copy content to clipboard in javascript
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