There is a way to download a file (instead of opening it) with HTML:
<a href="./images/myimage.png" download="myimage.png">Download</a>
What I am looking for is a way to do this with JavaScript. What I have is an AJAX call to retrieve a URL for an image:
function followUpFunction(){
if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
var status = (xmlHttp.status == 200) ? "good" : "bad";
var returnedImageURL = xmlHttp.responseText;
window.open(returnedImageURL);
return;
}
}
You can see that way I'm downloading it now is by using JavaScript's window.open
function.
The way it works now, the browser gives a pop-up window warning, which people don't like or don't notice, this ends up with many people not getting their download. I would prefer the image just download immediately like it does with my HTML snippet above. Also, I don't want the current window replaced or written over, I want it to remain visible just as it is.
So, is there a way I can do this with JavaScript?
Thanks!