I'm trying to read the contents of the clipboard using Javascript. With Internet Explorer it's possible using
window.clipdData.getData("Text")
Is there a similar way of reading the clipboard in Firefox, Safari and Chrome?
I'm trying to read the contents of the clipboard using Javascript. With Internet Explorer it's possible using
window.clipdData.getData("Text")
Is there a similar way of reading the clipboard in Firefox, Safari and Chrome?
I believe people use a hidden Flash element to read the clipboard data from the browsers you mentioned.
Dupe of this question: http://stackoverflow.com/questions/127040
In addition to the correct answer there, Flash 10 now only allows write-access to the clipboard during user interaction (eg. a click handler).
NO. And if you do find a hack (e.g. old version of flash) do not depend on it.
Can I ask why you want to read from the clipboard? If the user wants to pass along the clipboard contents, all they need to do is paste.
Safari supports reading the clipboard during onpaste
events:
You want to do something like:
someDomNode.onpaste = function(e) {
var paste = e.clipboardData && e.clipboardData.getData ?
e.clipboardData.getData('text/plain') : // Standard
window.clipboardData && window.clipboardData.getData ?
window.clipboardData.getData('Text') : // MS
false;
if(paste) {
// ...
}
};
Online Spreadsheets hook Ctrl+C, Ctrl+V events and transfer focus to a hidden TextArea control and either set it contents to desired new clipboard contents for copy or read its contents after the event had finished for paste.