StackOverflow_16689273: document-readystate-not-working-in-firefox-and-chrome

Illustration of answer to http://stackoverflow.com/questions/16689273/document-readystate-not-working-in-firefox-and-chrome.

by ExpertSystem

JavaScript

var frame = document.createElement("iframe");
document.body.appendChild(frame);
var debug = document.createElement("div");
debug.innerHTML = "iFrame's documents's state:<br />";
document.body.appendChild(debug);

frame.src = "http://fiddle.jshell.net/ExpertSystem/wD49T/show?" + Math.random();
var timer = setInterval(function() {
    var state = frame.contentWindow.document.readyState;
    if (state =="complete") { clearInterval(timer); }
    debug.innerHTML += state + "<br />";    
}, 100);

/* Stop the infinite loading loop after 5secs */
setTimeout(function() { frame.src = "about:blank"; }, 5000);