Dynamic iframe not loading occasionally in Firefox

I have JavaScript code that dynamically injects an iframe on a given HTML page. Unfortunately, in Firefox and only in Firefox, although an iframe is created from time to time, the corresponding URL does not load into it.

I know that it was not loaded because the corresponding URL does not appear on the Firebug Net tab, and when I check the iframe, I do not see the expected HTML code there (when the iframe is in the same domain as the source page). I do not see any JavaScript or network errors.

Here's a snippet of code, I checked all the relevant variables:

var iframe = document.createElement("iframe"); iframe.width = options["w"]; iframe.height = options["h"]; iframe.scrolling = "no"; iframe.marginWidth = 0; iframe.marginHeight = 0; iframe.frameBorder = 0; iframe.style.borderWidth = 0; if (node.childNodes.length > 0) node.insertBefore(iframe, node.childNodes[0]); else node.appendChild(iframe); iframe.contentWindow.location = iframeSrc + "?" + querystring; 

Here is an example of the URL that is set for the iframe (the problem is also recreated when the URL points to an external server, should omit "http: //" at the beginning, otherwise I could not send the question):

 127.0.0.1:8000/widget/iframe/index.html?style=slide-top-to-bottom&culture_code=en_us&c=26&sc=1324&title=Top%20News&caption=Top%20Stories&order=relevance&count=20&w=250&h=300&timestamp=true&scrollbar=false&theme=ui-lightness&className=8815455464592103&referrer=http%3A%2F%2F127.0.0.1%3A8000%2Fwidget%2Fbuilder%2Findex.html 

After doing some research on the Internet, I found this inapplicable Firefox error that seems to be related to this problem: https://bugzilla.mozilla.org/show_bug.cgi?id=279048

After reading the error, I tried several solutions, none of which solved the problem:

  • Setting iframe.src instead of iframe.contentWindow.location
  • Adding a random parameter to the query string
  • Add a '#' character with a random number at the end of the URL
  • Providing an iframe with a random name

Does anyone have a workaround for this annoying Firefox bug? Or is the problem I am describing not related to an error and has a different solution?

+6
javascript dom html firefox iframe
source share
2 answers

Having solved the problem, I was looking for the wrong place. The HTML file into which this dynamic iframe was loaded had an empty iframe tag that was removed from the DOM, after which a dynamic iframe was added instead.

Apparently, Firefox cached the last URL for this iframe and immediately loaded it when loading an external page. I know, because I saw that the corresponding HTML file is loaded twice on the Firebug Net tab, and not once upon injection.

After I got rid of this empty iframe tag and relied only on the injected iframe, everything started to work well and the problem no longer reproduced. I think Firefox didn’t like it, if there could be some kind of error with this script?

Thank you for helping me, it inspired me to make the right decision :)

+1
source share

What happens if you add this to the bottom of your script?

 iframe.contentWindow.location.reload(true); 

Perhaps this will stop the need for a reboot in FF.

EDIT

Fixed example

+5
source share

All Articles