Skip to content

Instantly share code, notes, and snippets.

@dannyid
Created September 25, 2015 06:34
Show Gist options
  • Save dannyid/cfc0fa982e5afd8b29cc to your computer and use it in GitHub Desktop.
Save dannyid/cfc0fa982e5afd8b29cc to your computer and use it in GitHub Desktop.
For use in a Chrome extension. Don't forget to enable the "clipboardWrite" permission.
function copyToClipboard(text) {
const input = document.createElement('input');
input.style.position = 'fixed';
input.style.opacity = 0;
input.value = text;
document.body.appendChild(input);
input.select();
document.execCommand('Copy');
document.body.removeChild(input);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment