FileSaver什么都不做

时间:2015-08-22 12:08:32

标签: javascript file filesaver.js

以下代码没有下载/保存有什么问题?

https://jsfiddle.net/36nuqrqm/



process.on('exit', () => {
    server.close();
})

process.on('uncaughtException', () => {
    server.close();

})

process.on('SIGTERM', () => {
    server.close();
})

function save_file()
{
	var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
	saveAs(blob, "hello world.txt");
}




我正在使用file saver

here是其工作代码的示例

1 个答案:

答案 0 :(得分:0)

在Frameworks&扩展使用No wrap-in而不是onLoad。

使用onLoad的结果:

<script type="text/javascript">//<![CDATA[
window.addEvent('load', function() {
function save_file()
{
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    saveAs(blob, "hello world.txt");
}
});//]]> 

</script>

结果使用无包装:

<script type="text/javascript">//<![CDATA[

function save_file()
{
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    saveAs(blob, "hello world.txt");
}
//]]> 

</script>

或者更好,使用onLoad的jquery https://jsfiddle.net/36nuqrqm/2/

<button id="export_to_csv">export to CSV</button>

$("#export_to_csv").on('click', function (){
    var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
    saveAs(blob, "hello world.txt");
})
相关问题