使用JavaScript启动文件下载 [英] starting file download with JavaScript

查看:127
本文介绍了使用JavaScript启动文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当点击这些链接时,向服务器发送一个AJAX请求,返回具有文件位置的URL。



我想做的是在响应恢复时直接浏览器下载文件。有没有可移植的方式来做到这一点?

解决方案

尝试这个lib https://github.com/PixelsCommander/Download-File-JS 它比以前描述的所有解决方案更现代,因为使用下载属性和组合方法带来最佳的体验。



在这里解释 - http://pixelscommander.com/en/javascript/javascript-file-downliading-ignore-content-type/



似乎是用JavaScript开始下载的理想代码片段。


Let's say I have download links for files on my site.

When clicked these links send an AJAX request to the server which returns the URL with the location of the file.

What I want to do is direct the browser to download the file when the response gets back. Is there a portable way to do this?

解决方案

Try this lib https://github.com/PixelsCommander/Download-File-JS it`s more modern than all solutions described before because uses "download" attribute and combination of methods to bring best possible experience.

Explained here - http://pixelscommander.com/en/javascript/javascript-file-downliading-ignore-content-type/

Seems to be ideal piece of code for starting downloading in JavaScript.

这篇关于使用JavaScript启动文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆