網(wǎng)頁下載文件期間如何防止用戶對網(wǎng)頁進行其他操作
更新時間:2014年06月27日 17:36:35 投稿:whsnow
網(wǎng)頁下載文件時需要一段時間,在這期間如何防止用戶對網(wǎng)頁進行其他操作,將div覆蓋在網(wǎng)頁上,將網(wǎng)頁鎖住,具體實現(xiàn)如下
做網(wǎng)頁下載文件時,有時候文件過大,生成文件需要一段時間。這個時候要防止用戶對網(wǎng)頁進行其他操作,有種方法就是使用一個div覆蓋在網(wǎng)頁上,將網(wǎng)頁鎖住。
function lockScreen()
{
sWidth=$(window).width();
sHeight=$(window).height();
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#CCCCCC";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
if(sWidth < 860)
{
bgObj.style.width="860px";
}
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);
}
使用如上函數(shù)可以鎖住頁面防止多次操作,要直到下載框出現(xiàn)時取消鎖屏。
在服務器端(cgi)中設置cookie:
<pre name="code" class="cpp">char *configDownloadToken = "finishedDownloadFile";
printf("Content-Type: application/octet-stream\nContent-Length: %ld\n", s.st_size);
printf( "Set-Cookie:configDownloadToken=%s; path=/; \r\n ",configDownloadToken);
printf("Content-Disposition: attachment; filename=\"%s\"\n", strrchr(filename,'/') + 1);
printf("Connection: close\n\n");
在客戶端(html、js)導入插件jquery.cookie.js,在html文件中要包含此插件,js文件中定時獲取cookie
var configDownloadCheckTimer;
$(document).ready(function () {
configDownloadCheckTimer = window.setInterval(function() {
var cookieValue = $.cookie('configDownloadToken');
if (cookieValue === "finishedDownloadFile")
{
refreshPage();
finishDownload();
}
}, 1000);
});
function finishDownload() {
window.clearInterval(configDownloadCheckTimer);
$.removeCookie('configDownloadToken'); //clears this cookie value
}
這樣就可以了。
相關文章
jquery.simple.tree插件 更簡單,兼容性更好的無限樹插件
在這里介紹一款小巧,功能強大,能拖拽,支持異步,且兼容性更高的jquery Tree插件2010-09-09
jquery select操作的日期聯(lián)動實現(xiàn)代碼
是很簡單的代碼 不過我自己操作的時候才發(fā)現(xiàn)我自己還有很多不懂,要多實際應用才發(fā)現(xiàn)問題,哎~~2009-12-12
jQuery ReferenceError: $ is not defined 錯誤的處理辦法
今天開始要學習jQuery,寫第一個Hello Word時,居然jQuery ReferenceError: $ is not defined2013-05-05

