Clipboard API and events
This document describes APIs for clipboard operations such as copy, cut and paste in web applications.
File API
This specification provides an API for representing file objects in web applications, as well as programmatically selecting them and accessing their data.
有了这些资料,其实实现起来也是so easy!!
//console.log(e)
var items = e.clipboardData.items;
for (var i = 0; i < items.length; ++i) {
var item = e.clipboardData.items[i];
if (items[i].kind == 'file' && items[i].type == 'image/png') {
//FileReader可以参考API
var fileReader = new FileReader();
//readAsDataURL是一个异步过程,这里提供回调方法
fileReader.onloadend = function () {
var d = this.result.substr( this.result.indexOf(',')+1);
var img = document.createElement("img");
img.src= "data:image/jpeg;base64,"+d;
document.body.appendChild(img);
};
//DataURL,不清楚了可以去看下资料
fileReader.readAsDataURL(item.getAsFile());
break;
// Just get one
}
}
};
</script>
</body>
</html>