chrome.downloads.download会忽略saveAs选项并打开对话框,无论 [英] chrome.downloads.download ignores saveAs option and opens the dialog regardless

查看:479
本文介绍了chrome.downloads.download会忽略saveAs选项并打开对话框,无论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个扩展程序,该扩展程序可以一次下载多个文件.

I'm trying to create an extension which downloads multiple files at once.

为此,我使用了chrome下载api,下面是代码(使用AngularJS):

In order to accomplish that, I'm using chrome downloads api, here is the code (with AngularJS):

var fileDownloadProperties = function(raw) {
    return {
      url: "https:" + raw.url,
      filename: sharedDir + "/" + raw.name + "pdf",
      saveAs: false
    }
};
$scope.status = "";
filesToDownload.forEach(function (raw) {
  chrome.downloads.download(fileDownloadProperties(raw));
});

问题在于,脚本运行时会忽略 saveAs 选项,并继续打开另存为"对话框(名称和位置正确传递,因为它们是对话框中的默认设置,但可能会被覆盖).

The problem is that when the script runs it ignores the saveAs option, and proceed with opening the save as dialog (the name and location are passed correctly, as they are the defaults in the dialog, but could be overwritten).

虽然它允许我下载,但是它并没有太大用,因为我可以拥有数十个文件(并且只有在上一个文件下载完成后,下一个保存对话框才会打开!).

While it does allow me to download, it's not very useful as I can have over tens of files (and the next save dialog will open only when the previous file finished downloading!).

是否有一种方法可以强制chrome静默同时下载文件?我尝试了其他解决方案(例如下面的代码),但似乎没有一个可以避免打开对话框.

Is there a way to force chrome to download files silently and simultaneously? I tried other solutions (like the code below), but none seems to avoid the dialog from opening.

var a = document.createElement("a");
a.href = files[0];
a.download = files[0];
a.click();  

任何帮助将不胜感激,谢谢.

Any help will be greatly appreciated, thanks.

推荐答案

您可以指示用户将Chrome设置设置为具有

You can instruct your user to set Chrome settings to have

Ask where to save each file before downloading

另存为"已打开/关闭.

"Save As" turned on/off.

https://lifehacker .com/make-chrome-ask-where-to-save-downloaded-files-by-chang-1790840372

这篇关于chrome.downloads.download会忽略saveAs选项并打开对话框,无论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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