【发布时间】:2020-09-16 23:21:33
【问题描述】:
该网站的目的是下载已签署同意书的图像。一切都在桌面上按我想要的方式运行,但不幸的是它在移动设备上不起作用。我尝试了 chrome、brave、firefox 和 safari。我要么显示图像但不下载,要么出现一些奇怪的页面失真。如何调整代码来修复它?
这是源代码: https://github.com/jacelecomte/wwvhSigns
处理图片保存的方法在这里:
function finalizeScreenshot() {
html2canvas(document.body).then(function (canvas) {
document.body.appendChild(canvas);
saveScreenshot(canvas);
});
}
function injectScript(uri) {
const document = window.document;
const script = document.createElement("script");
script.setAttribute("src", uri);
//document.body.appendChild(script);
}
function injectHtml2canvas() {
injectScript("//html2canvas.hertzen.com/dist/html2canvas.js");
}
injectScript('./src/html2canvas.js');
injectHtml2canvas();
finalizeScreenshot();
function saveScreenshot(canvas) {
const fileName = "Consent Form";
const link = document.createElement("a");
link.download = fileName + ".png";
//console.log(canvas);
canvas.toBlob(function (blob) {
console.log(blob);
link.href = URL.createObjectURL(blob);
link.click();
});
}
//these 3 functions are run in a row to create and download the screenshot.
injectScript('./src/html2canvas.js');
injectHtml2canvas();
finalizeScreenshot();
【问题讨论】:
标签: javascript html html2canvas