网页下载文件期间如何防止用户对网页进行其他操作
2014-06-27 00:00
891 查看
做网页下载文件时,有时候文件过大,生成文件需要一段时间。这个时候要防止用户对网页进行其他操作,有种方法就是使用一个div覆盖在网页上,将网页锁住。
使用如上函数可以锁住页面防止多次操作,要直到下载框出现时取消锁屏。
在服务器端(cgi)中设置cookie:
在客户端(html、js)导入插件jquery.cookie.js,在html文件中要包含此插件,js文件中定时获取cookie
这样就可以了。
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); }
使用如上函数可以锁住页面防止多次操作,要直到下载框出现时取消锁屏。
在服务器端(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 }
这样就可以了。
相关文章推荐
- 网页下载文件期间如何防止用户对网页进行其他操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作(远程开发)
- 如何在Phpstorm中设置FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- JSP 页面保存或者提交数据时,弹出浮层防止用户在保存过程中进行其他操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何在Webstorm/Phpstorm中设置连接FTP,并快速进行文件比较,上传下载,同步等操作
- 如何把Windows CE安装文件下载到本地进行安装
- 转:如何进行文件操作
- 如何解决下载的CHM文件无法显示网页问题
- 如何使用wget批量下载或递归下载网页中的所有文件
- 如何下载网页中的flash文件
- 如何使用proc文件系统让用户空间和内核空间进行交互
- SilverLight学习笔记--如何在xaml文件中操作用户在后台代码定义的类(1)--说明篇(原创)(转载本文请注明出处)
- 如何解决下载的CHM文件无法显示网页问题