美文网首页
使用JS粘贴图片

使用JS粘贴图片

作者: 蒋大培 | 来源:发表于2015-11-21 10:29 被阅读0次

相关代码:

// 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);
        }
    }
}

相关文章

网友评论

      本文标题:使用JS粘贴图片

      本文链接:https://www.haomeiwen.com/subject/gznlhttx.html