2011-02-26 32 views
1

我想DOMContentLoaded之前注入样式表和脚本。是否有可能运行DOMContentLoaded之前的东西吗?

在谷歌浏览器就可以使用run_at = document_start

是否有在Firefox插件类似的东西?我可以在gBrowser.addEventListener("DOMContentLoaded"之前运行吗?怎么样?

+0

你想只在特定页面注入样式表?如果没有,您可以使用样式表服务使它们全球可用于所有网站。 – 2011-02-26 18:26:39

+0

@Felix我需要特定的网站... – BrunoLM 2011-02-26 18:29:26

回答

1

我使用目前的解决方法是以下

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); 

DIVbody的第一要素,所以该节点之后它将加载。我不必等待整个页面。

相关问题