2010-11-16 81 views
0

有沒有方法從DOMContentLoaded發起的事件訪問DOM?從DOMContentLoaded事件訪問DOM?

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) { 
    //how to access to the DOM from aEvent?? 
    }, 
} 

https://developer.mozilla.org/en/Code_snippets/On_page_load

回答

1

onPageLoad您鏈接到顯示在頁面上就在第一行如何:

var doc = aEvent.originalTarget; // doc is document that triggered "onload" event 

這給你的網站的document元素。