search

Home  >  Q&A  >  body text

Unable to download file via HTML5's download attribute

<p>I'm trying to create a download link the way I've been doing it before. But now it keeps redirecting me to Google Docs - I've never encountered this before and it should be a simple task, so this is quite shocking to me. </p> <p>I used the HTML5 download attribute: </p> <pre class="brush:php;toolbar:false;"><a href="../files/uploads/myfile.docx" download>myfile.docx</a></pre> <p>But I always get redirected to Google Docs. I also opened the Chrome Developer Console and noticed that after I clicked on the link, it changed the href to Google Docs. I have absolutely no idea why this is happening. </p> <p>The path should be fine, I can't figure out the problem. what do I do? </p>
P粉642919823P粉642919823473 days ago489

reply all(1)I'll reply

  • P粉513318114

    P粉5133181142023-09-03 09:25:52

    The download attribute only applies to same-origin URLs. So if the href is different from the site's source, it won't work. In other words, you can only download files that belong to that website. This attribute follows the same rules outlined in the Same Origin Policy

    reply
    0
  • Cancelreply