Save File using Greasemonkey

前端 未结 6 2122
面向向阳花
面向向阳花 2020-12-09 04:21

I have some screen scraped tabular data that I want to export to a CSV file (currently I am just placing it in the clipboard), is there anyway to do this in Greasemonkey?

6条回答
  •  情书的邮戳
    2020-12-09 04:47

    var data='col1,col2\nval1,val2';
    var a = document.createElement('a');
    a.href = 'data:application/csv;charset=utf-8,' + encodeURIComponent(data);
    //supported by chrome 14+ and firefox 20+
    a.download = 'data.csv';
    //needed for firefox
    document.getElementsByTagName('body')[0].appendChild(a);
    //supported by chrome 20+ and firefox 5+
    a.click();
    

    DEMO

提交回复
热议问题