How to set a file name using window.open

前端 未结 4 1724
孤独总比滥情好
孤独总比滥情好 2020-11-28 05:44

I\'am trying to download temporary result calculated by JavaScript. Say I have a string str, I want to download a file contains str and named it as

4条回答
  •  时光取名叫无心
    2020-11-28 06:02

    A shorter version of accepted one (for my case had to use unicode)

    var link = document.createElement("a");
    link.href = 'data:text/csv,' + encodeURIComponent("algún texto");
    link.download = "Example.csv";
    link.click();
    

提交回复
热议问题