【问题标题】:msSaveOrOpenBlob work in Edge but not work in Edge WebViewmsSaveOrOpenBlob 在 Edge 中工作,但在 Edge WebView 中不起作用
【发布时间】:2019-10-22 21:16:02
【问题描述】:

现在 Office 加载项使用新的基于 Edge 的 WebView 而不是基于 IE 11 的。我的一段代码在此更新后停止工作。我只是尝试在这里下载文件。如果我在任何浏览器中使用此代码,它可以正常工作。但是 Excel 或 Word 等 Office 应用程序使用 Microsoft Edge 的 WebView 版本。调试告诉我在这种情况下函数 window.navigator.msSaveOrOpenBlob 是未定义的。请帮我解决它。

我尝试查找有关此问题的任何文档,但没有成功。

        function ClickFunc() {
        var blob = new Blob(['Some Byte Array'], { type: 'application/txt' });
        //output file name
        var fileName = "test.txt";

        //detect whether the browser is IE/Edge or another browser
        //
        //ERROR: In Edge WebView window.navigator.msSaveOrOpenBlob is undefined.  
        //
        if (window.navigator && window.navigator.msSaveOrOpenBlob) 
        {
        //To IE or Edge browser, using msSaveorOpenBlob method to download file.
            window.navigator.msSaveOrOpenBlob(blob, fileName);
        } else {
            //To another browser, create a tag to downlad file.
            //This part of code for browsers other than IE & Edge.
            const url = window.URL.createObjectURL(blob);
            const a = document.createElement('a');
            document.body.appendChild(a);
            a.setAttribute('style', 'display: none');
            a.href = url;
            a.download = fileName;
            a.click();

            window.URL.revokeObjectURL(url);
            a.remove();
        }
    }

   //I use this code in HTML to call function
   <button onclick="ClickFunc()">Click me</button>

window.navigator.msSaveOrOpenBlob 在 Microsoft Edge 的 WebView 中使用时未定义。

【问题讨论】:

    标签: javascript webview microsoft-edge office-addins


    【解决方案1】:

    您使用的是 Microsoft Edge WebView2 吗?如the article 中所述,Edge WebView2 使用 Microsoft Edge (Chromium) 作为渲染引擎。 msSaveOrOpenBlob 在 MS Edge 和 IE 中是专有的,在基于 Chromium 的 Edge 中是未定义的。

    【讨论】:

    • 感谢您的快速回答。我刚刚学会了你分享的文字。我确定我使用 WebView1 :-)。我没有安装 WebView2 SDK 或 Edge(Chromium),我通过通常的 Windows 和 Office 365 更新得到了这种新的痛苦。我想,我无法通过这种方式在开发人员预览中获得软件。我也有部分代码,它处理 Chrome 浏览器,它工作正常。就我而言,结果是访问被拒绝错误。
    • 我已经在 WebView1 中测试了msSaveOrOpenBlob 方法。确实该方法已从 WebView1 中删除。虽然 WebView 使用与 Edge 相同的内核,但是从 WebView 中删除了许多功能。
    • 最新消息是什么?有没有其他方法可以在 edge webview 中下载 blob 数据?
    • @YuZhou 我也面临同样的问题。请提供任何其他方式的帮助。
    • 你们找到解决办法了吗?我也面临同样的问题。
    猜你喜欢
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多