I have a HTML page that contains an <iframe>. The <iframe> is being refreshed on certain events (and I can see the contents of the <iframe> being changed, so as far all is ok).
What I want to do is add a onreadystatechange to the <iframe> so that I can display a "loading" text while the contents are being fetched.
I could not add the onreadystatechange in any browser (Safari, Chrome, Firefox). From what I found on the Internet it seems to work in IE, but this is no help for me.
I’ve tried:
<iframe onreadystatechange="function();">
document.getElementById('frameId').onreadystatechange = function() {};
document.getElementById('frameId').contentDocument.onreadystatechange = function() {};
but nothing seems to work.
So if you want to show a “The page is loading” message and hide this when the iframe has finished loading you can do something similar to the example below. Note that I used JQuery just to easen up this process. But obviously it can be done in 100% Javascript too.
I also created this on JSFiddle to show you the result. Check it here!!