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.
精彩评论