将CSS文件添加到带有扩展名初始化的页面



我正在阅读本教程

这就是CSS文件的加载方式:

var linkTargetFinder = function () {
    return {
        init : function () {
            gBrowser.addEventListener("load", function () {     
                // ...
                }
            }, false);
        },
        run : function () {
            var head = content.document.getElementsByTagName("head")[0],
            style = content.document.getElementById("link-target-finder-style")
            if (!style) {
                style = content.document.createElement("link");
                style.id = "link-target-finder-style";
                style.type = "text/css";
                style.rel = "stylesheet";
                style.href = "chrome://linktargetfinder/skin/skin.css";
                head.appendChild(style);
            }
            // ...
        }
    };
}();
window.addEventListener("load", linkTargetFinder.init, false);

我不明白为什么CSS文件不能注入到页面中init

var linkTargetFinder = function () {
    return {
        init : function () {
            gBrowser.addEventListener("load", function () {
                var head = content.document.getElementsByTagName("head")[0]
                style = content.document.createElement("link");
                style.id = "link-target-finder-style";
                style.type = "text/css";
                style.rel = "stylesheet";
                style.href = "chrome://linktargetfinder/skin/skin.css";
                head.appendChild(style);
                // ...
                }
            }, false);
        },
        run : function () {
            // ...
        }
    };
}();
window.addEventListener("load", linkTargetFinder.init, false);

样式在这种情况下不起作用。
为什么不能放在init

看起来很合理,但对于gBrowser事件,使用DOMContentLoaded而不是load

最新更新