Using HTML5/JavaScript to generate and save a file

后端 未结 17 1724
有刺的猬
有刺的猬 2020-11-21 07:30

I\'ve been fiddling with WebGL lately, and have gotten a Collada reader working. Problem is it\'s pretty slow (Collada is a very verbose format), so I\'m going to start conv

17条回答
  •  醉话见心
    2020-11-21 07:55

    I've used FileSaver (https://github.com/eligrey/FileSaver.js) and it works just fine.
    For example, I did this function to export logs displayed on a page.
    You have to pass an array for the instanciation of the Blob, so I just maybe didn't write this the right way, but it works for me.
    Just in case, be careful with the replace: this is the syntax to make this global, otherwise it will only replace the first one he meets.

    exportLogs : function(){
        var array = new Array();
    
        var str = $('#logs').html();
        array[0] = str.replace(/
    /g, '\n\t'); var blob = new Blob(array, {type: "text/plain;charset=utf-8"}); saveAs(blob, "example.log"); }

提交回复
热议问题