gpt4 book ai didi

javascript - 火狐扩展 : How to access page element via jQuery?

转载 作者:行者123 更新时间:2023-11-28 20:22:10 25 4
gpt4 key购买 nike

我正在使用以下代码:

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

关于javascript - 火狐扩展 : How to access page element via jQuery?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18083629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com