I am trying to write code for Safari to handle the insert event, but it looks like it is not working correctly. According to the WebKit DOM link, oncut , onpaste and oncopy processed more or less than the W3C clipboard API offers. However, this does not work as I expect. I am inserting image data, but as far as I could tell, the problem I am facing is with any type of paste. This jsfiddle works 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 only plain JS . There is no joy yet:
<div id="pastearea" onpaste="plainjsOnPaste()" style="width: 100px; height: 100px; background-color: blue;"/> function plainjsOnPaste(e) { console.log("blahblahblah"); console.log(e); }
If there is a problem with Safari, then obviously I should not expect jQuery to work. As far as I can tell, in the second attempt (simple) I do exactly what the link to WebKit offers, but this does not work at all. Is this some of Safari's famous limitation, or is it a problem between the chair and the keyboard?
Update: Safari doesn't seem to be implementing the W3C Clipboard APIs working draft. I am exploring workarounds, but if anyone knows, I would love to hear that.
javascript safari javascript-events
Ben collins
source share