I'm trying to dynamically set the value for the download attribute of an anchor. This should be the file name of the downloaded file. However, the filename is defaulting to its original value, not the value I'm trying to give it.
EDIT: It was pointed out that the download attribute value IS actually getting changed in the DOM. However, the filename of the file downloaded is not properly assigned.
EDIT: Does not seem to be a problem with dynamically set value. Even hard-coded, the filename is not getting set.
<a href="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png" download="image.png">click</a>
http://jsfiddle.net/abalter/2wz5zs7r/
HTML:
<button>Set url and download name for anchor</button>
<a href="" download="">Download Google logo</a>
Javascript:
var googleLogoURL = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
$('button').on('click', function(){
alert("url and filename set");
$('a').prop({
'href': googleLogoURL,
'download': "google-logo.png"
});
});