How to download file with javascript?

前端 未结 3 826
南笙
南笙 2021-01-12 13:44

I want to be able to download a given file when pressing a button.The file will be provided via an API call.For now, I will have it in my local storage. So my f

3条回答
  •  [愿得一人]
    2021-01-12 14:50

    You can provide the link to this function to download the file :

    function downloadURI(uri, name) 
    {
        var link = document.createElement("a");
        link.download = name;
        link.href = uri;
        link.click();
    }
    

提交回复
热议问题