js download a file, the file to determine whether to return

  Before downloading using window.location.href download, but can not determine whether the documents returned, small files just fine, do not download large files for a long time and no loading bar or something, users sometimes click to download at several large data service is easy to wear down, so I decided the next improvement, the god of online reference, probably thinking is: ifram tags Download, appended to the document, remove the download is complete, the front end of a cookie with a time stamp, the background reception, after the download is complete return of the function to the front end of a timed cycle time stamp verification is not returned, if it is confirmed that the download was successful

  Front-end code:

  

$ ( "# mylink") the Click (. function () {
                 var iframe = document.createElement ( "iframe" );
                 // specified path iframe 
                iframe.src = dss.rootPath + "plugin / sjwfx / NineAddressNoLeisUreExport" ; 
                $ ( iframes.) .css ( "Run the display", "none" );
                 // start "data loading" progress bar, prompts the user to export data 
                dss.alert ( "you are exporting data. Please wait a moment" ); 
                DSS .load ( to true );
                 // append elements to the document 
                document.body.appendChild (iframe);
                // every second cycle at which the code, if the value of I is returned to close the loading 
                var= the setInterval interval The ( function () {
                     // Get returned Cookie 
                    var Down = dss.cookie.get ( "resultId" );
                     IF (Down == "75,941,785" ) {
                         // hide "Data Loading" progress bar 
                        dss .load ( to false ); 
                        $ (iframes) .remove (); 
                        // close the loop function of time 
                        the clearInterval (interval the); 
                    } 
                }, 1000 ); 

            });

 

Add background so few lines of code:

     Cookie = cookie new new cookie ( "resultId", "75,941,785"); // time stamp set to the cookie 
        cookie.setPath ( "/"); // may occur distal js not read, so the settings 
        cookie. setMaxAge (10); // set the cookie lifetime, adjustable smaller 
        response.addCookie (cookie); // add cookie

 

I did not bring the front end of a time stamp, because the relationship between the iframe, this is my iframe embedded in an iframe inside, I can not read the cookie back up band, Baidu a lot of no good solution, so I was directly in the background bring value, identify the front end, I set up a time of ten seconds cookie fail, attention: background If the profile is configured with http-only, front-end js is not a read operation, there is not setPath must take, if not read the front, try vaginal discharge, or specify the name of your project.

 

Guess you like

Origin www.cnblogs.com/grasslucky/p/10945209.html