js模拟用户多次点击下载文件

/**
 * 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);
		});
	}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值