0

So I have an issue where I have a button on my page that has a link to a dmg file however when you press the button it opens the dmg in the browser instead of downloading it.

I have tried using the download attribute but with no success.

My code:

<button id="DownloadByOS" class="btn btn-lg btn-primary btn-block mt-3" onclick="location.href=somerandom.dmg">Download</button>
Lucas
  • 598
  • 9
  • 18
  • 2
    Does this answer your question? [How to trigger a file download when clicking an HTML button or JavaScript](https://stackoverflow.com/questions/11620698/how-to-trigger-a-file-download-when-clicking-an-html-button-or-javascript) – JGof Apr 22 '20 at 23:28
  • I'm afraid not I'm gunna have to remake the question as it got immediately closed – Lucas Apr 22 '20 at 23:45

1 Answers1

0

The value you want to assign to location.href is a string, but somerandom.dmg has not be wrapped in quotation marks.

<button id="DownloadByOS" class="btn btn-lg btn-primary btn-block mt-3" onclick=" location.href='somerandom.dmg' ">Download</button>
Kana Ki
  • 179
  • 1
  • 5