Iframe.readyState does not work in chrome

后端 未结 4 879
长情又很酷
长情又很酷 2020-11-30 08:17

I create an Iframe on the fly and set as the url a page that downloads a binary file (xls, doc...). While files are downloading I show an animation. When do

4条回答
  •  旧巷少年郎
    2020-11-30 09:10

    The downloadable file content doesn't trigger the readystatechange event handler or the onload event handler. This couse you can set a cookie in server side together the file content, and client side check this cookie periodically. For example:

    server

    response.cookie('fileDownloaded','true');
    response.header('attachment','your-file-name.any');
    //...write bytes to response...
    

    client

    var checker = setInterval(()=>{
        if(document.cookie.indexOf('fileDownloaded')>-1){
            alert('done');
            clearInterval(checker);
        }
    },100);
    

    Of course, you can use your framework to check the cookie value correctly, this is just a poc, not a safe cookie parser.

提交回复
热议问题