I'm trying to write some code for Safari for handling the 'paste' event, but it doesn't seem to work right. According to the WebKit DOM reference, oncut
, onpaste
, and oncopy
are all handled more-or-less like the W3C Clipboard API suggests. However, it doesn't work like I expect. I'm pasting image data, but as far as I've been able to tell, the problem I'm having applies to any kind of paste. This jsfiddle works just fine in Chrome, but not in Safari 6.0.4 on OSX.
$(function () {
console.log("ready");
$("#pastearea").on("paste", function (e) {
e.preventDefault();
console.debug("testing paste in safari");
var blob = e.originalEvent.clipboardData.items[0].getAsFile();
console.debug(blob);
var reader = new FileReader();
reader.onload = readerLoaded;
reader.readAsDataURL(blob);
});
});
function readerLoaded(e) {
$("#dest").attr("src", e.target.result);
}
I tried again using just plain JS. Still no joy:
<div id="pastearea" onpaste="plainjsOnPaste()" style="width: 100px; height: 100px; background-color: blue;"/>
function plainjsOnPaste(e) {
console.log("blahblahblah");
console.log(e);
}
If there's some issue with Safari, then obviously I shouldn't expect jQuery to work. As far as I can tell, in the second attempt (plain) I'm doing exactly what the WebKit reference suggests I should do, but it doesn't work at all. Is this some known limitation of Safari, or is the problem between the chair and keyboard?
Update: it seems that Safari doesn't implement the W3C's working draft of the Clipboard APIs. I'm researching workarounds, but if anyone knows one I'd love to heard it.