/** * 通过reader方式生成dataurl图片 * @param event */ functionhandlePaste(event) { var items = (event.clipboardData || event.originalEvent.clipboardData).items; console.log(JSON.stringify(items)); // will give you the mime types var blob = items[0].getAsFile(); var reader = new FileReader(); reader.onload = function(event){ console.log(event.target.result)}; // data url! reader.readAsDataURL(blob); }
/** * createObjectURL方式,创建图片文件 * @param e */ functionhandlePaste2(e) { var items = e.originalEvent.clipboardData.items;
for (var i = 0; i < items.length; ++i) { console.log(items[i].type); if (items[i].kind == 'file' && items[i].type == 'image/png') { var blob = items[i].getAsFile(); var img = document.createElement('img'); img.src = window.URL? window.URL.createObjectURL(blob) : window.webkitURL.createObjectURL(blob); $("#js_editor").html(img); } } };