Home > Software design >  Can't download file using HTML5 download attribute
Can't download file using HTML5 download attribute

Time:12-08

I'm trying to create a download link the way it always worked for me. But now it keeps redirecting me to Google Docs – I've never experienced that before, this should be a straight-forward task to do, so it quite shocked me.

I use the HTML5 download attribute:

<a href="../files/uploads/myfile.docx" download>myfile.docx</a>

But I always end up redirected to Google Docs. I also opened the Chrome dev console and noticed that after I click on the link, it changes the href to Google Docs. I have no clue why.

The path should be alright, I can't figure out the problem. What shall I do?

CodePudding user response:

The download attribute only works for same-originl URLs. So if the href is not the same origin as the site, it won't work. In other words, you can only download files that belongs to that website. This attribute follows the same rules outline in the same-origin policy

CodePudding user response:

The download attribute specifies that the target will be downloaded when a user clicks on the hyperlinks.

  • Related