2013-10-31 63 views
2

我在目錄中創建了一個填充文件名的表。現在我想從上傳的目錄下載這些文件。我得到多個文件名,然後解析它們以逐個發送它們。我用這段代碼對它進行了處理,但它只下載了最後一個文件。多下載使用javascript

while (dowloadParts[i] != "") 
    { 
    window.location = "http://" + window.location.host + "/Uploads/" + dowloadParts[i]; 
    } 

我應該怎麼做,以家政多個文件下載。

+0

嘗試此鏈接http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/ –

回答

3

我解決了我爲每個單獨的下載文件請求創建iframe的問題。這是我的代碼;

 function downloadFile(filesForDownload) { 
     i = 0; 
     var downloadParts = filesForDownload.split(';'); 

     while (downloadParts[i] != "") { 

      downloadURL("http://" + window.location.host + "/Uploads/" + downloadParts[i]); 
      i++; 
     } 
    } 
    var count = 0; 


    var downloadURL = function downloadURL(url) { 

     var hiddenIFrameID = 'hiddenDownloader' + count++; 
     var iframe = document.createElement('iframe'); 
     iframe.id = hiddenIFrameID; 
     iframe.style.display = 'none'; 
     document.body.appendChild(iframe); 
     iframe.src = url; 
    }