download file from any url

Solutions on MaxInterview for download file from any url by the best coders in the world

showing results for - "download file from any url"
Michele
11 Apr 2019
1function download(url, filename) {
2fetch(url).then(function(t) {
3    return t.blob().then((b)=>{
4        var a = document.createElement("a");
5        a.href = URL.createObjectURL(b);
6        a.setAttribute("download", filename);
7        a.click();
8    }
9    );
10});
11}
12
13download("https://get.geojs.io/v1/ip/geo.json","geoip.json")
14download("data:text/html,HelloWorld!", "helloWorld.txt");