SOLVED: View the answer below marked SOLVED. Thanks.
I am trying to download a file from location specified by url on click. I am using a delegate but when the button clicks the browser navigates to the location of the file and displays the contents. I want the click to trigger the browser’s download dialog.
Here is the code:
$('#left').delegate("a", "click", function(event){
//alert("CLICKED");
event.preventDefault();
window.location.href = url;
});
All posts regarding this question says to use the “event.preventDefault();” but that does not work for me. Does anyone have any suggestions?
You may need to change the server side (if you are able to).
The http response must contain the header:
So the browser knows that it must open the download dialog. Otherwise the browser will try to open/preview it.
More info:
Microsoft Support