我在 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);
试试这个如果有效的话
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();
}}