0

I wrote a JS code to download pdf and zip files into the browser. For pdf download everything works fine. But for zip download, it's not working for ISO(15.3.1) chrome and firefox. But this works fine for the safari browser. Before updating the version(15.1) it was working fine for all browsers. I also tried using https://github.com/eligrey/FileSaver.js but the same problem exists.

let req = new XMLHttpRequest();
req.open("POST", url);
req.responseType = "blob";
req.onreadystatechange = function () {
    if (req.response != null && req.status === 200) {
        let link = document.createElement('a');
        link.href = URL.createObjectURL(req.response);
        link.download = $currComponent.find(".downloadFileName").val() + "." + req.response.type.split("/")[1];
        link.click();
        link.remove();
    }
};
req.send(JSON.stringify(data));

Here I added the code that I worked with.

  • Please try to define what is not working? Do you get an error message or what is happening? – rsz Apr 22 '22 at 15:09
  • @rsz I didn't get any error. Codes are perfectly running. But don't understand why the download is not working for Mozilla & Chrome. – sady rifat Apr 25 '22 at 05:59
  • I suggest you try appending the created anchor tag `a` to the html body (or wherever you need it) and then click on it. After that you can remove the node from HTML, this is then in turn less tricky. – rsz Apr 26 '22 at 16:08
  • let link = document.createElement('a'); In this line, I tried to do the same thing. Are you telling me to do it another way? – sady rifat Apr 28 '22 at 09:26
  • you are just creating an anchor element, what the difference would be, you would append it to the HTML on the site, this way it would be something like what you see for this SO answer https://stackoverflow.com/a/4772817/1430562 you would need to append the created anchor element to the HTML and then click on it, after that you can remove it freely – rsz Apr 29 '22 at 10:38
  • Not Working in iOS chorme & firefox Working Any other idea why blob is not downloading? @rsz – sady rifat May 05 '22 at 09:14

0 Answers0