How To Use Window.onload?
I'm refactoring a website using MVC. What was a set of huge pages with javascript, php, html etc etc is becoming a series of controllers and views. I'm trying to do it in a modular
Solution 1:
You can attach a handler to the window load event with js, so you don't need the markup.
// crossbrowser event binding from http://www.quirksmode.org/js/eventSimple.html//function addEventSimple(obj,evt,fn) {// if (obj.addEventListener)// obj.addEventListener(evt,fn,false);// else if (obj.attachEvent)// obj.attachEvent('on'+evt,fn);//}// using Google API's event functions
GEvent.addDomListener(window, "load", load);
GEvent.addDomListener(window, "unload", GUnload);
functionload() {
// your load function
}
Drop that in a script tag on your view and the load function will be called once the window is loaded.
The google API probably also provides a way to attach the load event, but I'm not familiar with it.
Post a Comment for "How To Use Window.onload?"