-2

I want to make a download button, I have this line of code but it opens the txt file in Google:

      <a href="data/info.txt" download="data/info.txt">Download
      <button class="btn" style:height: 200px; width: 100px; download><i class="fa fa-download"></i> Download</button>
      </a>
AleksanderGD
  • 414
  • 5
  • 10
  • 4
    Having a link around a button is... very strange. Which one is the user clicking? Why not just use the link and style it to look like a button? Seems like it'd be easier to control its behavior that way. – David Aug 14 '20 at 13:41
  • 3
    It is invalid HTML to have a `button` within an `a`. – Heretic Monkey Aug 14 '20 at 13:41
  • Does this answer your question? [How to force browser to download file?](https://stackoverflow.com/questions/6520231/how-to-force-browser-to-download-file) – Heretic Monkey Aug 14 '20 at 13:42
  • https://stackoverflow.com/questions/5192917/force-download-through-js-or-query – Moray Aug 14 '20 at 13:47

2 Answers2

-1

As far as I know download should be a filename, not a path. Does changing download to download="info.txt" work?

Exelian
  • 5,749
  • 1
  • 30
  • 49
-2

Which browser do you use? When I click on this button

<a href="info.txt" download="data/info.txt">
  <button class="btn" style:height: 200px; width: 100px; download>
    Download
  </button>
</a>

Chrome starts downloading the file. I've tried it on this page

Max
  • 52
  • 6