打印Windows 10 Javascript应用商店应用程序时出错
从Windows Universal Javascript应用程序打印更大的html页面时,我大多数时候都会出错。随着文档大小的增加,此错误发生的频率更高(通常会发生2页文档)。“我的文档”已完全加载并正确显示在“打印预览”窗口(在该窗口中选择“打印机”),包括多页文档。当我按下打印按钮时,在应用程序崩溃并在生产中关闭或崩溃并在开发中出现错误之前,它可能打印文档的一部分,也可能不打印。iframe和html/css似乎不是问题,因为预览显示正确。我还尝试过使用ms webview,结果也一样。谢谢你的建议 Visual Studio崩溃点: preview.js[dynamic]位于 533 Printer.setPageCount(TotalDisplayPages()) Visual Studio错误消息: 中第533行第1列的未处理异常res://edgehtml.dll/preview.js 0x80010108-JavaScript运行时错误:调用的对象已与其客户端断开连接 我的代码:打印Windows 10 Javascript应用商店应用程序时出错,javascript,printing,win-universal-app,Javascript,Printing,Win Universal App,从Windows Universal Javascript应用程序打印更大的html页面时,我大多数时候都会出错。随着文档大小的增加,此错误发生的频率更高(通常会发生2页文档)。“我的文档”已完全加载并正确显示在“打印预览”窗口(在该窗口中选择“打印机”),包括多页文档。当我按下打印按钮时,在应用程序崩溃并在生产中关闭或崩溃并在开发中出现错误之前,它可能打印文档的一部分,也可能不打印。iframe和html/css似乎不是问题,因为预览显示正确。我还尝试过使用ms webview,结果也一样。谢
var doc = "<!DOCTYPE html><html><head>" + style + "</head><body>" + html + "</body></html>";
var IFrame = document.createElement('iframe');
IFrame.frameBorder = 0;
IFrame.src = "";
IFrame.width = "200px";
IFrame.height = "200px";
document.body.appendChild(IFrame);
IFrame.contentWindow.document.open();
IFrame.contentWindow.document.write(doc);
IFrame.contentWindow.document.close();
var printManager = Windows.Graphics.Printing.PrintManager.getForCurrentView();
printManager.onprinttaskrequested = function (printEvent) {
var printTask = printEvent.request.createPrintTask("Print", function (args) {
var deferral = args.getDeferral();
MSApp.getHtmlPrintDocumentSourceAsync(IFrame.contentWindow.document).then(
function (source) {
args.setSource(source);
deferral.complete();
}, function (error) {
console.log("Printing: " + error);
deferral.complete();
});
});
printTask.oncompleted = function () {
console.log("Printing: oncompleted");
};
};
Windows.Graphics.Printing.PrintManager.showPrintUIAsync();
var doc=”“+style+“”+html+“”;
var IFrame=document.createElement('IFrame');
IFrame.frameBorder=0;
IFrame.src=“”;
IFrame.width=“200px”;
IFrame.height=“200px”;
document.body.appendChild(IFrame);
IFrame.contentWindow.document.open();
IFrame.contentWindow.document.write(doc);
IFrame.contentWindow.document.close();
var printManager=Windows.Graphics.Printing.printManager.getForCurrentView();
printManager.onprinttaskrequested=函数(printEvent){
var printTask=printEvent.request.createPrintTask(“打印”,函数(args){
var deferral=args.getDeferral();
MSApp.getHtmlPrintDocumentSourceAsync(IFrame.contentWindow.document),然后(
函数(源){
args.setSource(源);
延迟。完成();
},函数(错误){
console.log(“打印:+错误);
延迟。完成();
});
});
printTask.oncompleted=函数(){
console.log(“打印:未完成”);
};
};
Windows.Graphics.Printing.PrintManager.showPrintUIAsync();