Mario Galvão
Mario Galvão

Reputation: 41

Chrome download multiple files

On Chrome last update, my web site stopped working. The code below for downloading multiple files is not working anymore, and it`s opening just the last file on the same tab. My Chrome options is set to accept multiple downloads from my website, as it was before this last update.

Could you please tell me how to solve this problem?

for (i = 0; i < photosURL.length; i++) {
    var downloadLink = document.createElement("a");
    downloadLink.href = photosURL[i];
    downloadLink.download = "foto_id_" + [i];
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);
}

Upvotes: 4

Views: 1625

Answers (1)

mehulmpt
mehulmpt

Reputation: 16597

Try this:

for (i = 0; i < photosURL.length; i++) {

    var downloadLink = document.createElement("a");
    downloadLink.target = "_blank"; // new tab
    downloadLink.href = photosURL[i];
    downloadLink.download = "foto_id_" + [i];

    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

}

Upvotes: 3

Related Questions