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×tamp=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?
javascript dom html firefox iframe
Ido schacham
source share