国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

網(wǎng)頁下載文件期間如何防止用戶對網(wǎng)頁進行其他操作

2019-11-20 14:23:39
字體:
供稿:網(wǎng)友

做網(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 } 

這樣就可以了。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉义县| 乌鲁木齐市| 翁牛特旗| 双鸭山市| 中卫市| 蓝田县| 玉溪市| 北票市| 临汾市| 榕江县| 顺平县| 慈利县| 青川县| 曲阳县| 沙湾县| 三亚市| 隆回县| 宜黄县| 徐州市| 贺兰县| 澄江县| 青铜峡市| 溧阳市| 郁南县| 永宁县| 连城县| 延寿县| 宾川县| 西城区| 花垣县| 隆昌县| 成武县| 县级市| 临夏县| 石阡县| 永康市| 南阳市| 洛扎县| 丹寨县| 无极县| 定陶县|