javascript - How to have a specific file name when download -


this question has answer here:

i've made function create csv file using json. i've found tips have button in order download file, i'm having issues have file name "*****.csv". need have extension ".csv" couldn't find topics dealing that.

here code :

function json2csv() {    var myjson = "http://******/get_json_test.php?callback=?";    $('.filter').each(function(i, obj){      var input = $(obj).find("input")[0];      myjson += '&'+input.name+'=' + input.value;   });    $('.display').each(function(i,obj){      myjson += '&'+$(obj).attr('table')+'|'+$(obj).attr('titre')+'';   });    $.getjson(myjson, function(data){      var line = '';      var str = '';         if(data.length != 0){            $.each(data[0], function(index, valeur){ //pour chaque colonne               var line = '';               var value = index;               line += value + ';';               str += line; //+ '\r\n';            });            str = str.slice(0, -1);            str += '\n';             $.each(data, function(i,ti){               $.each(ti, function(index, valeur){                  var line = '';                  var valeur = valeur;                  line += valeur + ';';                  str += line; // + '\r\n';               });            str = str.slice(0, -1);            str += '\n';            }); //end each         window.open("data:application/str;charset=utf-8," + encodeuricomponent(str));         } //end if   }); //end getjson } //end json2csv 

would know have write in "window.open" line ?

thanks.

use header: content-disposition: attachment; filename="downloaded.csv"


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -