Created
November 10, 2012 13:23
-
-
Save aolde/4051042 to your computer and use it in GitHub Desktop.
Clipboard in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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