前端文件下载 兼容所有浏览器
download.js文件下载,几乎支持所有类型下载,详细内容参考官网
http://danml.com/download.html
引入文件
<script src='//js.zapjs.com/js/download.js'></script>
html
<body>
<ul>
<li><a onclick="downloadFiles('/images/test.txt')" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下载txt文件</a></li>
<li><a onclick="downloadFiles('/images/test.rar')" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下载rar压缩文件</a></li>
<li><a onclick="downloadFiles('/images/test.html')" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下载html文件</a></li>
<li><a onclick="downloadFiles('/images/test.png')" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下载图片</a></li>
<li><a onclick="downloadFiles('/images/test.js')" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下载js文件</a></li>
<li><a onclick="downloadFiles('/images/test.mp3')" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下载媒体文件</a></li>
</ul>
</body>
js
function downloadFiles(url) {
download(url);
}