发送多个文件到用户下载一个接一个 [英] Send multiple files to the user for download one after another

查看:125
本文介绍了发送多个文件到用户下载一个接一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行以下操作:

I'm trying to do the following:


  • 向用户显示具有大量文件的网格

  • 用户根据需要选择尽可能多的文件

  • 应该提示用户为目标位置的每个文件

  • 每个文件应该相继下载

  • A grid with a lot of files is shown to the user
  • The user selects as many files as he wants
  • The user should be prompted for each file for the target location
  • Each file should be downloaded one after another

我找不到一个很好的解决方案,因为:

I can't find a good solution for this because:


  • 我需要一个跨浏览器解决方案(没有插件),但我可以依靠IE10 +和HTML5

  • 不应该下载这些文件作为zip文件或任何其他存档

  • 使用 document.write 插入多个iframe感觉不好,大多数浏览器都不鼓励

  • I need a cross browser solution (no plugins) but i can rely on IE10+ and HTML5
  • The files should not be downloaded as a zip file or any other archive
  • Using document.write for inserting multiple iframes feels bad and is discouraged by most browsers

推荐答案

我发现在所有浏览器中都有一个解决方案(适用于我)。它在代码方面并不觉得(起初),但是对于不同的浏览器和不同的机器来说,它似乎非常稳定。

I found a solution that works (for me) in all browsers. It's does not feel that good on the code side (at first) but it seems pretty stable to me on different browsers and different machines.

Chrome将要求用户允许该站点下载多个文件。 IE不在乎。

Chrome will ask the user to allow the site to download multiple files. IE doesn't care at all.

var onDownload = function(){
       var docs = module.getSelectedElements();        

       for(var i = 0; i < docs.length; i ++) {
           (function(){
               var doc = docs[i];
               window.setTimeout(function(){
                  $jq("#downloadIframe").attr("src", doc.url);
               }, i * 500);
           })();
       }

};

这篇关于发送多个文件到用户下载一个接一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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