我使用以下代码:
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);
它不断给出未定义的错误
解决方法:
$()默认使用当前窗口的文档.在你的情况下,这实际上是browser.xul.你需要对你已经通过var doc = aEvent.originalTarget;获得的子文档进行操作,所以这应该工作我认为(未经测试)
$(doc).find("#blueBar")