-1

In my Java Script , I am getting the below element from HTML. After getting it I want to save it in some folder on my local drive. Can any one help me with this.I am using zip.js to unzip files. After unzipping , all the zip file content coming in fileList and it is shown in the browser . When i click any one of the file it will get downloaded but instead showing it on browser I want to download all files in local drive after unzipping. Please see --gildas-lormeau.github.io/zip.js/demos/demo2.html

var fileList = document.getElementById("file-list");
Mani
  • 1
  • 2
  • 1
    It is not clear just by `data` that what you are going to save . – manikant gautam Apr 05 '19 at 05:56
  • I am using zip.js to unzip files. After unzipping , all the zip file content coming in fileList and it is shown in the browser . When i click any one of the file it will get downloaded but instead showing it on browser I want to download all files in local drive after unzipping. Please see --https://gildas-lormeau.github.io/zip.js/demos/demo2.html – Mani Apr 05 '19 at 06:00
  • Please have a look into the question https://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript You might need to restructure your HTML code and it will enable possibility for the user to download attached files – volna Apr 05 '19 at 07:03

1 Answers1

0

If your code is same as the demo, then you can loop through the li elements inside fileList and call click function on each of the links.

const fileList = $("#file-list"); //get file-list element by id
const li = fileList.children;     //get li elements inside fileList
for (let item of li) {            //loop through all li elements
    item.children.item(0).click() //get 1st child element (link) and click it to download
}

Note I used jQuery as the demo site allowed it, but if it is not possible for you then you can also use plain JavaScript.

Cray
  • 2,347
  • 7
  • 17
  • 27
  • Using it can i saved it in some target folder provided by user? – Mani Apr 05 '19 at 07:01
  • Download folders are specified by browser settings, you [can't](https://stackoverflow.com/questions/33612566/how-to-specify-download-location-in-html-using-javascript) change it through JavaScript – Cray Apr 05 '19 at 07:08
  • So how can i Unzipp a zip file and saved in a folder automatically using zip.js – Mani Apr 05 '19 at 07:10
  • As i said it is up to the user to select their download folder in browser settings, if you need to use browser and JavaScript for unzipping you have to use that selected folder. – Cray Apr 05 '19 at 07:22