首页 > 解决方案 > UWP getHtmlPrintDocumentSourceAsync 问题(与 x-ms-webview 一起使用时)

问题描述

我的应用程序使用 x-ms-webview 来满足其他要求。我们创建 HTML 元素 x-ms-webview 并将其添加到 DOM。在其功能完成后,我们将其从 DOM 中移除。

我的应用程序还使用 Windows 文档打印。它使用 Windows.Graphics.Printing(PrintManager.ShowPrintUIAsync)。使用 API MSApp.getHtmlPrintDocumentSourceAsync(page) 将要打印的数据转换为 HTMLDocumnentSource

我注意到这个错误,每当从 DOM 中删除 x-ms-webview 时,MSApp.getHtmlPrintDocumentSourceAsync(page) 都会
在 res://edgehtml.dll/preview.js 的第 357 行第 1 列抛出以下错误未处理异常​0x8000ffff - JavaScript 运行时错误:意外调用方法或属性访问

这是示例代码

1. Create a sample Cordova UWP app.
2. Add the x-ms-webview for example on button click as shown below


     var wv =  document.createElement('x-ms-webview'); // Use CSS to  set width, height and other styles
        wv.navigate("https://www.example.com");
         wv.id = "test145";
3. Now remove the web view on another action as shown below:
    var obj1=  document.getElementById(“test145”)
    obj1.parentNode.removeChild(obj1)
4. Try to perform printing, invoke as shown below:
    Windows.Graphics.Printing.PrintManager.showPrintUIAsync()

从 DOM 中删除 x-ms-webview 会导致此问题。如果我隐藏 webview,则看不到问题。有谁知道这些打印机 API 对 webview 的依赖关系。有什么解决方法吗?

标签: javascriptwindowscordovawebviewuwp

解决方案


推荐阅读