【发布时间】:2019-09-24 16:39:12
【问题描述】:
我搜索了很多,但没有找到从剪贴板获取 base64 编码的数据。我可以捕捉粘贴事件,然后用这个将事件分配给变量
clipBoard = e.clipboardData ? e.clipboardData : window.clipboardData;
在铬;我可以得到已经粘贴的打印屏幕,像这样
if (clipBoard.types[0] == "Files") {
var blob = clipBoard.items[0].getAsFile();
var reader = new FileReader();
reader.onload = function(event){
console.log(event.target.result);
}; // data url!
reader.readAsDataURL(blob);
}
但在 ie 11 中,clipBoard 变量没有“项目”或“类型”。我将上传该图像服务器,但我没有得到 base64 编码数据。
【问题讨论】:
-
顺便说一句,如果您需要 url 最终结果,您应该更喜欢 URL.createObject() 而不是 FileReader();它比 FileReader() 更快、更简单(没有回调),并且可以处理更大的文件。
-
我不太懂js。你能提供一些示例代码吗?
标签: javascript clipboard internet-explorer-11