As the title states, I'm trying to prompt the user when they download a file that is being hosted on my server. I thought the browser took care of this automatically (and I guess in a way, it does) but it seems that the file is just downloaded automatically if the file type cannot be rendered, and it navigates to another page with the file if it can be rendered. I want the 'save as' and 'run' prompt to pop up every single time the user selects to download a file from my server, regardless if the browser can render it or not.
Here is my current code:
download: function(path) {
path = getServerPath(path);
//var a = document.createElement('a');
//a.href = path + (session ? "?gttoken="+ session.token : "");
//a.click();
location.href = path + (session ? "?gttoken="+ session.token : "");
},
The commented portion was my initial code, the token is needed to be allowed access to the file. How can I modify my code to prevent automatic downloads and bring up the prompt every single time?
P.S - Guess I should mention that it needs to work on latest version of IE, and preferably IE 10+.
Thanks!
Try using a content type of attachment. See details here: http://www.jtricks.com/bits/content_disposition.html