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

来源:互联网 发布:大神小的知错了书包网 编辑:程序博客网 时间:2024/05/17 00:07
<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" onclick="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 fieldresponse.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 responseresponse.Flush();




1 0