js 插件下载方法在 MacBook 中不起作用

问题描述 投票:0回答:1

我在 Word 插件中使用下载方法,它可以在 Windows 和 Web 中运行,并且可以在 MacBook 浏览器中运行,但不能在 MacBook Office 365 Word 应用程序中运行。 这是我的代码

   const blobUrl = URL.createObjectURL(blob);

   var link = document.createElement("a");
   link.download = fileName;
   link.target = "_blank";
   // Construct the URI
   link.href = blobUrl;
   document.body.appendChild(link);

   setTimeout(function () {
       link.click();
       // Cleanup the DOM
       document.body.removeChild(link);
       DOWNLOAD_COMPLETED = true;
   }, 500);

javascript office365 office-addins add-in word-addins
1个回答
0
投票

试试这个如果有效的话

    function SaveToDisk(fileURL, fileName) {
// for non-IE
if (!window.ActiveXObject) {
    var save = document.createElement('a');
    save.href = fileURL;
    save.target = '_blank';
    save.download = fileName || 'unknown';

    var evt = new MouseEvent('click', {
        'view': window,
        'bubbles': true,
        'cancelable': false
    });
    save.dispatchEvent(evt);

    (window.URL || window.webkitURL).revokeObjectURL(save.href);
}

// for IE < 11
else if ( !! window.ActiveXObject && document.execCommand)     {
    var _window = window.open(fileURL, '_blank');
    _window.document.close();
    _window.document.execCommand('SaveAs', true, fileName || fileURL)
    _window.close();
}}
© www.soinside.com 2019 - 2024. All rights reserved.