Download indicator remains in Firefox after iframe download is complete

I have an iframe placed in my page body as follows:

<iframe src="about:blank" onload="this.contentWindow.document.write('some text')"> 

It works quite well, the onload event replaces the contents of the iframe with "some text" and thus it.

BUT in Firefox, it calls the โ€œspinning wheelโ€ loading indicator, which indicates that the page is loading so that it never leaves. Only text is inserted in the iframe, so there is no other content hanging around waiting to load. When I remove the iframe from the page, this fixes the problem, so I know that it is the called iframe that calls it.

It works correctly in IE and Chrome.

Now I can do something like this:

  <iframe src="about:blank" onload="this.contentWindow.document.write('some text'); t.contentWindow.stop();"> 

What problem is fixed in Firefox, but it prevents the loading of any images in the iframe (I do not use them in the example of inserting text, but they will be added later).

So how can I fix this?

+7
javascript html firefox load
source share
2 answers

Make sure you call this.contentWindow.document.close (); after writing to iframe.

+13
source share

Why do you start writing to contentWindow using the load event of the same iframe in the first place?

An alternative approach simply creates an iframe and loads some content with images into it - it works on firefox, as expected. Nothing wrong.

 <!DOCTYPE html> <html> <head> <script type="text/javascript"> function createIframe(){ var f = document.getElementsByTagName('body') [0].appendChild(document.createElement('iframe')); f.contentWindow.document.write('<img src="http://www.funimage.org/uploads/posts/2013-02/1361892989_1_14.jpg" />'); } </script> </head> <body onload="createIframe()"> </body> </html> 
+1
source share

All Articles