js模拟用户多次点击下载文件
2016-04-21 17:00
531 查看
/** * Javascript 多文件下载 * 动态创建a标签,模拟用户多次点击 */ function download_files(files) { function download_next(i) { if(i>=files.length) { return; } var a = document.createElement('a'); a.href = files[i]; a.target = '_parent'; // Use a.download if available, it prevents plugins from opening. if ('download' in a) { a.download = files[i].filename; } // Add a to the doc for click to work. (document.body || document.documentElement).appendChild(a); if (a.click) { a.click(); // The click method is supported by most browsers. } else { $(a).click(); // Backup using jquery } // Delete the temporary link. a.parentNode.removeChild(a); // Download the next file with a small timeout. The timeout is necessary // for IE, which will otherwise only download the first file. setTimeout(function () { download_next(i + 1); }, 500); } // Initiate the first download. download_next(0); }
//调用时传入file文件名数组
function multiDown(){
var contentsId = $("#contentsId").val();
if(contentsId == "" || contentsId == null){
return ;
}
//E07007
if($("input[type='checkbox'][name='fileNameCk']:checked").length == 0){
warningShow("E07007",getErrorMessage("0","E07007",""));
return;
}
//E07006
confirmationShow("E07006",getErrorMessage("0","E07006",""),function(){
var fName = new Array();
$("input[type='checkbox'][name='fileNameCk']:checked").each(function(){
fName.push($(this).val());
})
//E00008
var files = new Array();
for(var i = 0;i<fName.length;i++){
files.push(
"ContentsDetail!download2.action?status=multi&" +
"fileAttachFileName="+encodeURIComponent(fName[i])+"&contentsDto.contentsId="+$("#contentsId").val()
);
}
download_files(files);
});
}
相关文章推荐
- Extjs4.0 最新最全视频教程
- Javascript中toFixed方法的改进
- 5个常见可用性错误和解决方案
- js数组实现图片轮播
- js可突破windows弹退效果代码
- JSP脚本漏洞面面观
- 使用BAT一句话命令实现快速合并JS、CSS
- js显示当前星期的起止日期的脚本
- 爆炸式的JS圆形浮动菜单特效代码
- js select常用操作控制代码
- JS实现不使用图片仿Windows右键菜单效果代码
- 从jsp发送动态图像
- 原生js结合html5制作小飞龙的简易跳球
- js 页面模块自由拖动实例
- js实现小鱼吐泡泡在页面游动特效
- js 提交和设置表单的值
- PHP VBS JS 函数 对照表
- node.js抓取并分析网页内容有无特殊内容的js文件
- PHP+JS实现大规模数据提交的方法
- 仿51JOB的地区选择效果(可选择多个地区)