October 10, 2008
onload event in javascript
Nikolai Kordulla
0 comments >>
You can add a to the body tag. But what, if you want to change the onload event programatically, or if you cant change the body tag?
Just use this code (tested on safari, chrom, ie6, ie7 and firefox):
/* for Mozilla */
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
document.write("<script defer src='http://coderpeek.com/js/ie_onload.js'><"+"/script>");
/*@end @*/
/* for other browsers */
window.onload = init;