📜  从任何 url 下载文件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:13.592000             🧑  作者: Mango

代码示例1
function download(url, filename) {
fetch(url).then(function(t) {
    return t.blob().then((b)=>{
        var a = document.createElement("a");
        a.href = URL.createObjectURL(b);
        a.setAttribute("download", filename);
        a.click();
    }
    );
});
}

download("https://get.geojs.io/v1/ip/geo.json","geoip.json")
download("data:text/html,HelloWorld!", "helloWorld.txt");