Advertisement
Guest User

Copy to clipboard

a guest
Sep 27th, 2017
1,756
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                 document.getElementById("copyToClipboard").addEventListener("click", function () {
  2.                     var input = document.getElementById("clipboardSource");
  3.                     input.select();
  4.                     var successful = document.execCommand("copy");
  5.                     if (successful) {
  6.                         alert('Copied "' + input.value + '" to your clipboard.');
  7.                     } else {
  8.                         throw new Error("Failed to copy text (verify caller was in the context of an event handler)");
  9.                     }
  10.                 });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement