使用JS粘贴图片

相关代码:

// window.addEventListener('paste', ... or
document.onpaste = function(event) {
    var items = (event.clipboardData || event.originalEvent.clipboardData).items;
    //console.log(JSON.stringify(items)); // will give you the mime types
    for (index in items) {
        var item = items[index];
        if (item.kind === 'file') {
            var blob = item.getAsFile();
            var reader = new FileReader();
            reader.onload = function(event) {
                console.log(event.target.result)
            }; // data url!
            reader.readAsDataURL(blob);
        }
    }
}

推荐阅读更多精彩内容