Take the 2-minute tour ×

I need to dispatch the window's load event in javascript. There is plenty of documentation on how to dispatch mouse events, But I can't find any on load events. It only needs to work in firefox. It would be equally helpful if I could "spy" on the window's load event, because then I could just call the function. Using the "Event spy" addon isn't working because it requires me to open the dom inspector, which i can't do until after the page is finished loading. I'm making a grease monkey script. So I don't know which function it is that I'm trying to invoke.

share|improve this question
Why don't you just handle the onload event and call that handler explicitly instead of firing the onload event? –  Myles Nov 8 '09 at 17:45
add comment

2 Answers

HTML events are fired differently than mouse events. Here is how to fire a load event:

var load_event = document.createEvent("HTMLEvents");
load_event.initEvent("load", true, true);
share|improve this answer
add comment
var load_event = document.createEvent('Event');  
load_event.initEvent('load', false, false);  

works fine in my environment.

share|improve this answer
add comment

Your Answer


