开发者

Is it possible to run something before DOMContentLoaded?

I want to inject stylesheets and scripts before DOMContentLoaded.

In Google Chrome it is possible using run_at = d开发者_StackOverflow中文版ocument_start.

Is there something similar in Firefox addons? Can I run things before gBrowser.addEventListener("DOMContentLoaded" ? How?


The current workaround I'm using is the following

gBrowser.addEventListener("DOMNodeInserted",
    function (e)
    {
        if (typeof(e.relatedNode.tagName) != "undefined" &&
            e.relatedNode.tagName == "DIV")
        {
            var window = e.relatedNode.ownerDocument.defaultView;
            if (window.MyScript) return; // if it was injected
                                         // ignore other events
            if (/siteregex/i.test(window.location.href))
            {
                Initialize(window); // inject scripts
            }
        }
    },
    true);

DIV is the first element on body, so it will load right after this node. I won't have to wait for the whole page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜