Reputation: 2898
Hi I want to have the option on my site for the user to download a CSV file. I have used the code below
<input type="button" value="Download as CSV file" onclick="window.location.href='call_log.csv' " />
This does work but when the button is clicked the file is opened in another tab on my browser, What I want to happen is a download straight to the users default download folder
Can anyone help me please ?
Thanks
Upvotes: 2
Views: 3457
Reputation: 1313
I'm doing the same for my portfolio and I found a very simple way to download my cv as pdf from my website's local files.
I made a link <a>
as a button.
<a class="resume-btn" href="./resumes/UX Resume.pdf"> UX </a>
I tried it on Firefox, Opera, and Chrome, it works fine.
Upvotes: 1
Reputation: 135
If you just make a ordinary link to the file, the browser should not leave the page it is on, but just download the file straight away:
<a href="call_log.csv">Link</a>
I know it works for a .zip file, but haven't tried with .csv
But if you are having problems you can try zip the csv :)
Upvotes: 0
Reputation: 17525
You need to modify the headers that the server sends out with your CSV file. You need to add this header:
Content-Disposition: attachment; filename="call_log.csv"
Upvotes: 4