Chrome 83 版本发布后,模式对话框中的文件下载不起作用 [英] After Chrome version 83 release, file download in modal dialog doesn't work

查看:15
本文介绍了Chrome 83 版本发布后,模式对话框中的文件下载不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Google Apps Script 来快速下载电子表格数据.

I use Google Apps Script to make download Spreadsheet data quickly.

前几天,下载功能突然不能用了.我的一些可以使用该功能的同事使用的chrome版本是81.0.4044.138(Official Build)以及不能使用的功能,chrome版本83.0.4103.61(官方Build)

Since several days before, download function doesn't work suddenly. Some of my coworkers who can use the function use chrome version 81.0.4044.138(Official Build) and who cannot use the function , chrome version 83.0.4103.61(Official Build)

(幸运的是右键单击并[另存为]工作)

(right-click and [save as] works fortunately)

我想知道我应该怎么做才能使一键下载功能再次激活.

I want to know what should I do to make one-click download function active again.

脚本如下.

/**
 * Adds a custom menu
 *
 * @param {Object} e The event parameter for a simple onOpen trigger.
 */
function onOpen(e) {
  SpreadsheetApp.getUi()
      .createMenu('Custom')
      .addItem('Download as XLSX', 'downloadXLS_GUI')
      .addToUi();
}


/**
 * Display a modal dialog with a single download link.
 *
 * From: http://stackoverflow.com/a/37336778/1677912
 */
function downloadXLS_GUI() {
  // Get current spreadsheet's ID, place in download URL
  var ssID = SpreadsheetApp.getActive().getId();
  var URL = 'https://docs.google.com/spreadsheets/d/'+ssID+'/export?format=xlsx';

  // Display a modal dialog box with download link.
  var htmlOutput = HtmlService
                  .createHtmlOutput('<a href="'+URL+'">Click to download</a>')
                  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
                  .setWidth(800)
                  .setHeight(600);
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Download XLS');
}

推荐答案

问题

无法通过模式对话框中的链接下载文件

Cannot download a file via link in modal dialog

原因

自 Chrome 83 起已弃用(因此出现问题).模态对话框是沙盒环境,因此您的脚本停止工作.如果你打开开发者工具(按f12),你会看到一个警告:

The ability to do so is deprecated since Chrome 83 (hence the issue). Modal dialogs are sandbox environments, therefore your script stopped working. If you open the developer tools (press f12), you will see a warning:

禁止下载.启动或实例化下载的帧被沙盒化,但未设置允许下载"标志.有关详细信息,请参阅 https://www.chromestatus.com/feature/5706745674465280.>

Download is disallowed. The frame initiating or instantiating the download is sandboxed, but the flag ‘allow-downloads’ is not set. See https://www.chromestatus.com/feature/5706745674465280 for more details.

向链接添加 download 属性可以缓解该部分,但您会遇到第二个警告:

Adding a download attribute to the link mitigates that part, but you will encounter the second warning:

资源被解释为 Document 但以 MIME 类型 application/vnd.openxmlformats-officedocument.spreadsheetml.sheet 传输

Resource interpreted as Document but transferred with MIME type application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

做什么

截至目前,关于此事有一个未决问题,并承诺allow-downloads 标志将被添加到 HtmlService.XFrameOptionsMode.ALLOWALL - 您可以通过 setXFrameOptionsMode 将选项添加到模态对话框并查找更新.

As of now, there is an open issue regarding the matter, and it is promised that the allow-downloads flag will be added to HtmlService.XFrameOptionsMode.ALLOWALL - you can add the option to modal dialog via setXFrameOptionsMode and look for the updates.

这篇关于Chrome 83 版本发布后,模式对话框中的文件下载不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆