Is there any way to specify a suggested filename when using data: URI?

前端 未结 16 1914
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 03:09

If for example you follow the link:

data:application/octet-stream;base64,SGVsbG8=

The browser will prompt you to download a file consisting of t

16条回答
  •  半阙折子戏
    2020-11-22 03:59

    Chrome makes this very simple these days:

    function saveContent(fileContents, fileName)
    {
        var link = document.createElement('a');
        link.download = fileName;
        link.href = 'data:,' + fileContents;
        link.click();
    }
    

提交回复
热议问题