I have a link with href and download attributes:
<a id="lnk" href="data:text/csv;charset=utf-8,1%2C2%2C3" download="my_file.csv">click to download</a>
When I click on it (for example, in Chrome), the csv file "my_file.csv" loads as intended.
Now I want this action to be called programmatically. Therefore, using jQuery, I try:
$('#lnk').click();
or
$('#lnk').trigger("click");
but the file is not uploaded.
Here is the code: http://jsbin.com/yereg/3/edit
I could copy the link address from the link, and then just use window.open:
window.open('data:text/csv;charset=utf-8,1%2C2%2C3');
but this way I canβt set the file name (the link has the attribute download="my_file.csv" ). This solution is great if there is a way to set the file name.
Note: in my case, Chrome and Firefox must be supported. I donβt care what other browsers are.
source share