Creating download prompt using purely javascript

前端 未结 4 1396
梦谈多话
梦谈多话 2020-12-21 12:21

I have some text data (say var a = \'Hello World From Javascript\';)in javascript variable in current window. I want to do the following through javascript-

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 13:16

    Triggering a file download without any server request

    Unfortunately this is not something you can do with normal browser capabilities. Something like flash or a browser-specific plugin will get you what you need, but security limitations within javascript will not let you download arbitrary data created within the browser.

    Also the 'data' url is not supported across all browser/version combinations. I am not sure if your users are constrained on what browser they are using or not but that may limit what you can do with that solution.

    Source: Triggering a file download without any server request

提交回复
热议问题