Search code examples
javascripteventsonloaddomcontentloaded

Plain JavaScript on-page-load event not working


The question is pretty simple: why is nither of those are working when they should? Tried in latest chrome and FF

document.addEventListener("DOMContentLoaded", function() {
  alert("window on domcontentready");
}, false);

window.onload = function() {
  alert("window on load");
}

http://jsfiddle.net/FHHgA/4/


Solution

  • The JavaScript is loaded on onload (inside jsfiddle), so onload won't fire, because it already fired. Switch onload to no wrap - in <head>.