Skip to content

Instantly share code, notes, and snippets.

@hallvors
Forked from JamesMGreene/clipboard.js
Last active January 4, 2016 07:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hallvors/8589631 to your computer and use it in GitHub Desktop.
Save hallvors/8589631 to your computer and use it in GitHub Desktop.
var btn = document.getElementById("copy-button");
btn.addEventListener("click", clickHandler, false);
function clickHandler(e) {
document.exeCommand('copy');
}
@JamesMGreene
Copy link

NOTE: You must also call preventDefault on the ClipboardEvent instance or the data won't successfully be put into the system/desktop clipboard.

@hallvors
Copy link
Author

Good point @JamesMGreene - updated gist, still wondering if we could get around that stupid gotcha.. :-(

@hallvors
Copy link
Author

hallvors commented May 8, 2015

(Synthetic events were not the way to go - document.execCommand('copy') is the old new thing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment