Save file Javascript with file name [duplicate]

Deviljhoskimberk1提出了一个问题:Save file Javascript with file name [duplicate],或许与您遇到的问题类似。

回答者mstrapArthur Clemens给出了该问题的处理方式:

Replace your "Save" button with an anchor link and set the new download attribute dynamically. Works in Chrome and Firefox:

var d = "ha";
$(this).attr("href", "data:image/png;base64,abcdefghijklmnop").attr("download", "file-" + d + ".png");

Here's a working example with the name set as the current date: http://jsfiddle.net/Qjvb3/

Here a compatibility table for downloadattribute: http://caniuse.com/download

希望本文对你有帮助,欢迎支持JavaScript中文网