Triggering CSV download using Javascript?
Posted
by Sam Lee
on Stack Overflow
See other posts from Stack Overflow
or by Sam Lee
Published on 2010-06-14T23:06:19Z
Indexed on
2010/06/14
23:12 UTC
Read the original article
Hit count: 238
csv
|http-header-fields
I have an url /reportcsv
that generates a plain text csv with Content-type: text/csv
and Content-disposition: attachment; filename=report.csv
. I want trigger this csv to be downloaded using Javascript. I'm considering two methods:
1) Setting location.href = /reportcsv
2) Setting an iframe url to /reportcsv
Both seem to work in Safari. I was wondering if there is any difference between them, or if one is recommended over the other. My main requirement is that I don't want the user to leave the current page.
© Stack Overflow or respective owner