Ale*_*xee 5 javascript html2canvas
我已经使用html2canvas.js来截取特定 div 的屏幕截图,现在我想知道是否可以使用 js 将canvas元素作为图像复制到剪贴板,然后用户只需单击即可在剪贴板上获得他们想要的图像,他们所需要做的就是粘贴它。
小智 6
它仅适用于 https 或 localhost:
function getScreenShot(Src){
let src = document.getElementById(Src);
html2canvas(src).then(function(canvas) {
document.getElementById("explain-scr").appendChild(canvas);
canvas.toBlob(function(blob) {
navigator.clipboard
.write([
new ClipboardItem(
Object.defineProperty({}, blob.type, {
value: blob,
enumerable: true
})
)
])
.then(function() {
// do something
});
});
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4578 次 |
| 最近记录: |