document.addEventListener("paste", function (event) {
var isChrome = false;
if (event.clipboardData || event.originalEvent) {
//某些chrome版本使用的是event.originalEvent
var clipboardData =
event.clipboardData || event.originalEvent.clipboardData;
if (clipboardData.items) {
// for chrome
var items = clipboardData.items,
len = items.length,
blob = null;
isChrome = true;
for (var i = 0; i < len; i++) {
if (items[i].type.indexOf("image") !== -1) {
//getAsFile() 此方法只是living standard firefox ie11 并不支持
blob = items[i].getAsFile();
}
}
if (blob !== null) {
var reader = new FileReader();
reader.readAsDataURL(blob);
//base64码显示
reader.onload = function (event) {
// event.target.result 即为图片的Base64编码字符串
var base64_str = event.target.result;
};
// blob对象
// var blobUrl = URL.createObjectURL(blob);
// var fd = new FormData(document.forms[0]);
// fd.append("the_file", blob, "image.png");
}
}
}
});