相关疑难解决方法(0)

iframe.readyState在chrome中不起作用

我动态创建一个Iframe,并将一个下载二进制文件的页面设置为url (xls,doc ...).在下载文件时,我会显示一个动画.什么时候不,我隐藏它.

问题是Chrome不知道文件何时完全下载,即iframe完全加载的时间.我使用iframe属性readyState来检查iframe状态:

var iframe = document.createElement("iframe");
iframe.style.visibility = "hidden";
// I start a progress animation
window.setTimeout(showProgressAnimation, 1000);
// I start the file download
iframe.src ='GetFile.aspx?file=' + fileName;
document.body.appendChild(iframe);


function showProgressAnimation() {
   if (iframe.readyState == "complete" || iframe.readyState == "interactive") {
      // I stop the animation and show the page
      animation.style.display = 'none';
      progressBar.hide();
      $('#page').show();
   }
   else {
      // Chrome is always getting into this line
      window.setTimeout(showProgressAnimation, 1000);
   }
}
Run Code Online (Sandbox Code Playgroud)

所以结果是无限循环.

我尝试了以下内容,它可以在Firefox和Chrome中使用,在内容是二进制文件时却 …

html javascript asp.net iframe jquery

30
推荐指数
2
解决办法
3万
查看次数

标签 统计

asp.net ×1

html ×1

iframe ×1

javascript ×1

jquery ×1