I am trying to make a button force download a PDF, but I can’t figure out how, I am using an onclick function to count the number of times the button was clicked, but I want it to also force download the PDF here is my code:
I would suggest adding an event listener to the JavaScript rather than an onClick handler in the HTML.
You should be able to do the following:
<a href="#" download="proposed_file_name">Download</a>
<!--Just Replace the filename with your filename to the file
and you should be good to go-->
Also You may want to look into fixing the HTML, the button encompasses everything to include the amount of times downloaded.
<button type="button" onClick="onClick()">
<b>Download Game</b><!--Don't need this-->
<!--Place the A tag for the download here-->
</button>
<p>
<b>Downloads: <a id="clicks">0</a> </b>
<!--I would suggest using strong tags instead of the B tag
and replace the A tag with a simple paragraph tag-->
</p>