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

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

问题描述

假设我有我网站上文件的下载链接.

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

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?

推荐答案

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

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.

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

似乎是开始在 JavaScript 中下载的理想代码.

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

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

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