Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (37 sloc) 1.14 KB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>剪贴板操作</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="result" style="width: 100px;height: 100px"></div>
</body>
<script>
document.addEventListener('paste', function (e) {
console.info(e);
const cbd = e.clipboardData;
const fr = new FileReader();
const html = '';
for (let i = 0; i < cbd.items.length; i++) {
const item = cbd.items[i];
console.info(item);
if (item.kind == "file") {
const blob = item.getAsFile();
if (blob.size === 0) {
return;
}
console.info(blob);
fr.readAsDataURL(blob);
fr.onload = function (e) {
const result = document.getElementById("result");
//显示文件
result.innerHTML = '<img src="' + this.result + '" alt="" />';
}
}
}
});
</script>
</html>
You can’t perform that action at this time.