我無法在頁面中創建新元素。當頁面加載時,我檢查頁面和域名,這是工作,但我不知道如何在正確的窗口頁面中創建新元素。如何使用firefox插件中的jQuery和Javascript?
window.addEventListener("load", function() { myExtension.init(); }, false);
var myExtension = {
init: function() {
var appcontent = document.getElementById("appcontent"); // browser
if(appcontent)
appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true);
},
onPageLoad: function(aEvent) {
var unsafeWin = aEvent.target.defaultView;
if (unsafeWin.wrappedJSObject) unsafeWin = unsafeWin.wrappedJSObject;
var locationis = new XPCNativeWrapper(unsafeWin, "location").location;
var hostis = locationis.host;
//alert(hostis);
if(hostis=='domain.com')
{
var pathnameis=locationis.pathname;
if(pathnameis=='/index.php')
{
$("#left .box:eq(0)").after('<div id="organic-tabs" class="box"></div>'); // this code somewhy doesn't working, but if I copy to FireBug it't work.
}
}
}
}
我的問題是:如何使用JavaScript和jQuery從Firefox插件時,我想操縱HTML在正確的窗口內容?從這裏需要什麼
$("#left .box:eq(0)").after('<div id="organic-tabs" class="box"></div>');
工作。
你確定代碼甚至被執行?你是否在if語句中嘗試alert(或console.logs)? – roselan
您是否在使用Mozilla的[Add-On SDK](https://addons.mozilla.org/en-US/developers/builder)構建您的擴展? – Binary9
if(pathnameis =='/ index.php') { alert('something'); //其作品! } 我沒有使用插件bulder,是的,我用sdk(Komodo)和我壓縮它,(但不是拉鍊是問題,因爲菜單正在工作!) – golddragon007