Skip to content

Instantly share code, notes, and snippets.

@lucasbrigida
Forked from JamesMGreene/clipboard.js
Last active August 29, 2015 14:06
Show Gist options
  • Save lucasbrigida/f6755fca0062f7ff78c5 to your computer and use it in GitHub Desktop.
Save lucasbrigida/f6755fca0062f7ff78c5 to your computer and use it in GitHub Desktop.
var btn = document.getElementById("copy-button");
btn.addEventListener("click", clickHandler, false);
btn.addEventListener("copy", copyHandler, false);
function clickHandler(e) {
e.target.dispatchEvent(new ClipboardEvent("copy"));
}
function copyHandler(e) {
e.clipboardData.setData("text/plain", "Simulated copy. Yay!");
// CRITICAL: Must call `preventDefault();` to get this data into the system/desktop clipboard!!!
e.preventDefault();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment