2

我正在单击按钮创建一个文件并将其发送给用户以下载它。

我正在使用 jQuery blockUi 在执行时显示一条消息。

我想取消blockUi直到下载执行

我怎样才能做到这一点?

我创建文件并在创建文件末尾使用处理程序发送给用户我写了一个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));
4

0 回答 0