动态 iframe 在 Firefox 上不可见

Dynamic iframe not visible on Firefox

本文关键字:Firefox iframe 动态      更新时间:2023-09-26

我正在尝试使用KangoExtensions构建浏览器扩展。

我将以下 iframe 附加到正文:

<iframe id="iframe" name="iframe" allowtransparency="yes"
    style="position: absolute; top: -41px; left: 0px; right: 0px; width: 100%; height: 41px; z-index: 10000; border: 0px none;">
</iframe>

附加 iframe 后,我尝试编写内容:

window.onload= function(){
   $(iframe).ready(function(){
                var iframeDocument = false;
                if(iframe.contentDocument) {
                    iframeDocument = iframe.contentDocument;
                } else if(iframe.contentWindow) {
                    iframeDocument = iframe.contentWindow.document;
                } else if(window.frames['iframe'].document) {
                    iframeDocument = window.frames['iframe'].document;
                }
                if(iframeDocument) {
                    iframeDocument.open();
                    iframeDocument.write(content);
                }
            });
 };

该扩展程序适用于所有浏览器(Chrome,Opera,IE),但在Firefox中,它不会向iframe写入任何内容。如果我使用iframeDocument.body.innerHTML = content;内容可见几毫秒,然后消失。我只看到一个灰色的矩形。

在Firefox扩展中使用iframe有什么限制吗?

当您

尝试修改它时,似乎没有强制加载 iframe。

$(iframe).ready(function(){...})更改为iframe.addEventListener('load', function(){...})

您可以使用

$(iframe).load('data form server', function(){
    // ...
})