大型文件请考虑使用 filesaver.js
==============================================
主要解决页面内部动态获取下载文件url后,自动下载的问题。
新开一个标签页下载: window.open('url', '_blank');
这会导致屏幕新开标签页时的闪动,但浏览器兼容性好。
html5浏览器中, 可在本标签页中 无闪动开启下载:
$('<ahref="path_to_file"download="proposed_file_name">Download</a>')[0].click();path_to_fileis either an absolute or relative path,proposed_file_namethe filename to save to (can be blank, then defaults to the actual filename).
没有jquery时:
var a = document.createElement('a');
a.href = "path_to_file";
a.download = "proposed_file_name";
a.click();参考文献:


发布评论