0

我正在使用以下代码:

   var myExtension = {
    init: function() {
        // The event can be DOMContentLoaded, pageshow, pagehide, load or unload.
        if(gBrowser) gBrowser.addEventListener("DOMContentLoaded", this.onPageLoad, false);
    },
    onPageLoad: function(aEvent) {
        var doc = aEvent.originalTarget; // doc is document that triggered the event
        var win = doc.defaultView; // win is the window for the doc
        //alert("page is loaded \n" +doc.location.href);
       // alert(doc.location.href.indexOf("facebook.com"));
        if(doc.location.href.indexOf("facebook.com") == -1) 
        {
            return;
        }
        alert("we are here");
        alert($("#blueBar").html());
    }
}
window.addEventListener("load", function load(event){
    window.removeEventListener("load", load, false); //remove listener, no longer needed
    myExtension.init();  
},false);

一直undefined报错

4

1 回答 1

3

$()默认使用当前窗口的文档。在您的情况下,这实际上是 browser.xul。您需要对您已经通过的子文档进行操作var doc = aEvent.originalTarget;,所以我认为这应该可以工作(未经测试)

$(doc).find("#blueBar")
于 2013-08-06T15:26:54.933 回答