Organizational Research By

Surprising Reserch Topic

iframe readystate does not work in chrome

iframe readystate does not work in chrome  using -'javascript,jquery,,html,iframe'

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 does not, I hide it.

The problem is that Chrome does not know when the files are fully downloaded, that is when the iframe is completely loaded. I use the iframe property readyState to check the iframe state:

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

function showProgressAnimation() {
   if (iframe.readyState == "complete" || iframe.readyState == "interactive") {
      // I stop the animation and show the page = 'none';
   else {
      // Chrome is always getting into this line
      window.setTimeout(showProgressAnimation, 1000);

So the result is an infinite loop.

I've tried the following and it works in Firefox and Chrome but not when the contents are a binary file:

if ($.browser.mozilla || $.browser.webkit ) {
    iframe.onload = function showProgressAnimation() { = 'none';
// IE
     window.setTimeout(showProgressAnimation, 1000);


asked Oct 13, 2015 by manju bhargava
0 votes

Related Hot Questions

2 Answers

0 votes

You can use the onload to signaling the load of the iframe

here is a simple example that working

var iframe = document.createElement("iframe"); = "none";
// this function will called when the iframe loaded
iframe.onload = function (){ = "block";    
// set the src last.
iframe.src ='';

// add it to the page.

Tested here:
With src loaded last.

answered Oct 13, 2015 by amit_cmps
0 votes

Please try this - you are really mixing dom and jQuery from line to line

var tId;

function stopAnim() {
    // I stop the animation and show the page
var iframe = $("