How do i stop the browser following to the file in jquery? i want the file to just be downloaded?
$('#4').change(function () {
var name = this.value;
if (name !== "") {
if (confirm("Are you sure you want to download " + name)) {
$.ajax({
url: '/uploads/4/' + name,
type: 'HEAD',
error: function () { },
success: function () {
window.location.href = '/uploads/4/' + name;
}
});
}
}
});
This is how the code is now and it works but the file is displayed in the browser now downloaded?
Ive seen .preventDefault() but im not if this is what i need? or ow i should implement it if it is?
I think the user decide if some files (like if pdf are opened in the browser or downloaded) and you must set the correct header server side, in any case you could open the file in a new window so that the current page is not hidden