Skip to content

Instantly share code, notes, and snippets.

@robballou
Created June 2, 2020 15:41
Show Gist options
  • Save robballou/f5a0daa50ce065c91223775fe3cae09b to your computer and use it in GitHub Desktop.
Save robballou/f5a0daa50ce065c91223775fe3cae09b to your computer and use it in GitHub Desktop.
function copyItem(text) {
const tempElement = document.createElement('div');
tempElement.innerHTML = text;
const copy = (event) => {
if (event.clipboardData) {
event.clipboardData.setData('text/html', tempElement.innerHTML);
event.clipboardData.setData('text/plain', tempElement.innerHTML);
event.preventDefault();
}
};
document.addEventListener('copy', copy);
document.execCommand('copy');
document.removeEventListener('copy', copy);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment