我正在点击按钮创建一个文件并将其发送给用户下载。
我正在使用jQuery blockUi在执行时显示消息。
我想unblockUi直到下载执行
我该怎么做?
我创建文件并在创建文件结束时使用处理程序发送给用户我写了一个cookie并在jquery中检查cookie,如果cookie不为null则unblockUi:
<script type="text/javascript">
var fileDownloadCheckTimer;
function blockUIForDownload() {
if (IsCookiesEnable()) {
var token = new Date().getTime(); //use the current timestamp as the token value
$('#download_token_value_id').val(token);
$.blockUI({
message:$('#msg'),
css: {
padding: 0,
margin: 0,
width: '30%',
top: '40%',
left: '35%',
textAlign: 'center',
color: '#000',
border: '3px solid #aaa',
backgroundColor: '#fff',
cursor: 'wait',
}});
fileDownloadCheckTimer = window.setInterval(function () {
var cookieValue = $.cookie('fileDownloadToken');
//alert(cookieValue);
if (cookieValue != null)
finishDownload();
}, 1000);
// $('.blockOverlay').attr('title','Click to unblock').click($.unblockUI);
}
}
function IsCookiesEnable() {
var cookieEnabled = (navigator.cookieEnabled) ? true : false;
if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) {
document.cookie = "testcookie";
cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
}
return (cookieEnabled);
}
function finishDownload() {
window.clearInterval(fileDownloadCheckTimer);
$.cookie('fileDownloadToken', null);
$.unblockUI();
}
并在代码背后:
context.Response.AppendCookie(new HttpCookie("fileDownloadToken", _token));