Skip to content

Instantly share code, notes, and snippets.

@aolde
Created November 10, 2012 13:23
Show Gist options
  • Save aolde/4051042 to your computer and use it in GitHub Desktop.
Save aolde/4051042 to your computer and use it in GitHub Desktop.
Clipboard in JavaScript
Clipboard = {};
Clipboard.utilities = {};
Clipboard.utilities.createTextArea = function(value) {
var txt = document.createElement('textarea');
txt.style.position = "absolute";
txt.style.left = "-100%";
if (value != null)
txt.value = value;
document.body.appendChild(txt);
return txt;
};
Clipboard.copy = function(data) {
if (data == null) return;
var txt = Clipboard.utilities.createTextArea(data);
txt.select();
document.execCommand('Copy');
document.body.removeChild(txt);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment