How to export JavaScript array info to csv (on client side)?

前端 未结 29 1715
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 21:55

I know there are lot of questions of this nature but I need to do this using JavaScript. I am using Dojo 1.8 and have all the attribute info in array, which loo

29条回答
  •  后悔当初
    2020-11-21 22:57

    In Chrome 35 update, download attribute behavior was changed.

    https://code.google.com/p/chromium/issues/detail?id=373182

    to work this in chrome, use this

    var pom = document.createElement('a');
    var csvContent=csv; //here we load our csv data 
    var blob = new Blob([csvContent],{type: 'text/csv;charset=utf-8;'});
    var url = URL.createObjectURL(blob);
    pom.href = url;
    pom.setAttribute('download', 'foo.csv');
    pom.click();
    

提交回复
热议问题