It takes some time for a webpage to download files. During this period, how does one prevent users from performing other operations on the webpage, overwrite the div on the webpage, and lock the webpage, sometimes the file is too large and it takes some time to generate the file. To prevent other operations on the webpage, you can use a p to overwrite the webpage and lock the webpage.
function lockScreen() { sWidth=$(window).width(); sHeight=$(window).height(); var bgObj=document.createElement("p"); 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); }
Use the above function to lock the page to prevent multiple operations. You need to cancel the screen lock when the download box appears.
Set the cookie on the server (cgi:
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");
Import the jquery. cookie. js plug-in on the client (html, js). Include this plug-in the html file, and regularly obtain the cookie in the js file.
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 }
In this way, you can.