JS点击下载完毕后取消遮罩层

<html>
<head>
<script>
var w;
var timer;
function win(obj) {
	obj.disabled=true;
	w = window.open('xjpwb五笔.zip',"","toolbar=no, location=no, directories=no, status=no, menubar=no");
	timer = window.setInterval('ifWinClosed()',800);
}
function ifWinClosed(){
	if(w.closed == true){
		document.getElementById("click").disabled = false;
		window.clearInterval(timer);
	}
}
</script>
</head>
<body>
	<input type="button" name="click" value="click" id="click" οnclick="win(this);" />
</body>
</html>


2. 另外的较好方案请看下面链接,大概原理是:在服务器端生成cookie发给client,浏览器设置定时器一直检测是否收到此特定的cookie,收到了说明server下载完毕,响应完成。此时解除遮罩。

http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx

key code:

$(document).ready(function () {
    $('#create_pdf_form').submit(function () {
      blockUIForDownload();
    });
  });

  var fileDownloadCheckTimer;
  function blockUIForDownload() {
    var token = new Date().getTime(); //use the current timestamp as the token value
    $('#download_token_value_id').val(token);
    $.blockUI();
    fileDownloadCheckTimer = window.setInterval(function () {
      var cookieValue = $.cookie('fileDownloadToken');
      if (cookieValue == token)
       finishDownload();
    }, 1000);
  }
function finishDownload() {
 window.clearInterval(fileDownloadCheckTimer);
 $.removeCookie('fileDownloadToken'); //clears this cookie value
 $.unblockUI();
}

var response = HttpContext.Current.Response;
response.Clear();
response.AppendCookie(new HttpCookie("fileDownloadToken", downloadTokenValue); //downloadTokenValue will have been provided in the form submit via the hidden input field
response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", desiredFileName)); //desiredFileName will be whatever the resutling file name should be when downloaded

//Code to generate file and write file contents to response

response.Flush();




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值