Skip to content

Instantly share code, notes, and snippets.

@lankaapura
Created January 29, 2018 09:57
Show Gist options
  • Save lankaapura/7cbd320a63da8350a2c3ad573b079be0 to your computer and use it in GitHub Desktop.
Save lankaapura/7cbd320a63da8350a2c3ad573b079be0 to your computer and use it in GitHub Desktop.
function CopyToClipBoardHandler(value) {
const copyListener = event => {
document.removeEventListener('copy', copyListener, true);
event.preventDefault();
const clipboardData = event.clipboardData;
clipboardData.clearData();
clipboardData.setData('text/plain', value);
};
document.addEventListener('copy', copyListener, true);
document.execCommand('copy');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment