Download textarea contents as a file using only Javascript (no server-side)

前端 未结 8 2267
挽巷
挽巷 2020-11-29 03:44

I am being asked to make a \"download\" button that downloads the contents of a textarea on the same page as a file, with the browser\'s \"Save As...\" dialog showing up. Co

8条回答
  •  有刺的猬
    2020-11-29 03:54

    You could try window.location = "data:application/octet-stream,"+text but that doesn't provide a mechanism through which you can suggest a name, and also IE has a very small cap on the maximum length of a data URI which could be a problem.

提交回复
热议问题