Possible Duplicate:
Force download through js or query
I'm trying to write javascript which, when given a url, tells the user's browser to download the resource pointed to be the url. What I want is basically:
function download(url) { ... }
I can get the window to be set using window.open(url)
, but the problem is that the browser still gets to decide whether to display or download the file. Since I don't, from the javascript, have control over the MIME type, I need a way to, using javascript, instruct the browser to ignore the MIME type and download the resource. Basically the same thing that happens when you right-click a link and click "download" or the equivalent.
Side note: I've tried using the html5 tag's "download" attribute, and at least one browser (firefox) doesn't properly implement it at the moment, so that's off the table for now.