Skip to content

Instantly share code, notes, and snippets.

@mmiszy
Last active September 13, 2016 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmiszy/622ec101076540c980703c1d41e61982 to your computer and use it in GitHub Desktop.
Save mmiszy/622ec101076540c980703c1d41e61982 to your computer and use it in GitHub Desktop.
function onCopy(e) {
try {
e.clipboardData.setData('Text', 'tekst do skopiowania');
e.preventDefault();
} catch (err) {
console.error(err);
}
}
function onClick() {
try {
window.document.oncopy = onCopy;
window.document.execCommand('copy');
} catch (err) {
onError();
} finally {
window.document.oncopy = undefined;
}
}
button.addEventListener('click', onClick, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment