小编Ido*_*ham的帖子

Firefox中偶尔不会加载动态iframe

我有一些JavaScript代码,可以在给定的HTML页面中动态注入iframe.不幸的是,在Firefox中,只在Firefox中,虽然iframe是不时创建的,但相关的URL并没有加载到它中.

我知道它没有加载,因为相关的URL没有显示在Firebug Net选项卡中,当我检查iframe时,我没有看到任何预期的HTML代码(当iframe与外围的同一域时)页).我也没有看到任何JavaScript或网络错误.

这是一段代码片段,我检查了所有相关变量是否正确:

    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;
Run Code Online (Sandbox Code Playgroud)

这是为iframe设置的示例URL(当URL指向外部服务器时,该问题也会重新创建,必须在开头省略'http://',否则我无法发布问题):

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
Run Code Online (Sandbox Code Playgroud)

在网上做一些研究,我发现这个未修复的Firefox bug似乎与这个问题有关:https: //bugzilla.mozilla.org/show_bug.cgi?id = 279048

阅读完bug后,我尝试了几种解决方案,但没有解决问题:

  • 设置iframe.src而不是iframe.contentWindow.location
  • 将随机参数添加到查询字符串
  • 在URL的末尾添加带有随机数的"#"符号
  • 给iframe一个随机名称

有没有人有这个烦人的Firefox bug的解决方法?或者我描述的问题与错误无关并且有不同的解决方案?

html javascript iframe firefox dom

6
推荐指数
2
解决办法
4123
查看次数

标签 统计

dom ×1

firefox ×1

html ×1

iframe ×1

javascript ×1