I have implemented a downloader servlet using java as stated:
Implementing a simple file download servlet
The requirement is, on the browser side, the file should be automatically downloaded, not triggered by any anchor click. On the ajax response, I call
document.location = "downloadServlet?fileId=foo"
The problem is, it works fine for all desktop browsers, android mobile devices. But when the device is a iPad tablet, both chrome and safari do not download the file, for example if the file is a text file, the content is dumped to the page and my working page is lost. How can I force that the file is downloaded and not the content is shown? Even if trying a zip file for example, then the browser of tablet shows a different page and corrupts the working page. What I want is the browser downloads it as if performed SaveAs for all types of files.
Because the document.location changes the whole page on the iPad, I changed it to an anchor, but because it should be triggered automatically, I trigger the click event by
<a href="downloadServlet?.." target="_blank" rel="noopener" id="downloadAnchor" />
document.getElementById("downloadAnchor").click()
But then the popup blockers prevent the click event.