开发者

Accessing DOM from DOMContentLoaded event?

开发者 https://www.devze.com 2023-01-25 04:17 出处:网络
Is there a way to access the DOM from the event fired by DOMContentLoaded? window.addEventListener(\"load\", function() { myExtension.init(); }, false);

Is there a way to access the DOM from the event fired by DOMContentLoaded?

window.addEventListener("load", function() { myExtension.init(); }, false);

var myExtension = {
  init: function() {
    var appcontent = document.getElementById("appcontent");   // browser
    if(appcontent)
      appcontent.addEve开发者_如何学PythonntListener("DOMContentLoaded", myExtension.onPageLoad, true);
  },

  onPageLoad: function(aEvent) {
     //how to access to the DOM from aEvent??
  }, 
}

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


Just the first line in onPageLoad on the page you linked to shows how:

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

This gives you the document element of the website.

0

精彩评论

暂无评论...
验证码 换一张
取 消