How to add a page onload event
By liviu - Posted on June 5th, 2009
Tagged:
How to make a function execute when the page is loaded without putting it in the body tag with onload, but somewhere else in the page.
<script type="text/javascript">
var loadfunction = function() {
alert("Hello World 1");
}
function addEventSimple(obj,evt,fn) {
if (obj.addEventListener)
obj.addEventListener(evt,fn,false);
else if (obj.attachEvent)
obj.attachEvent('on'+evt,fn);
}
addEventSimple(window,'load',loadfunction);
</script>
Bookmark/Search this post with:
- liviu's blog
- Login or register to post comments
Delicious
Digg
StumbleUpon
Propeller
Reddit
Magnoliacom
Newsvine
Furl
Facebook
Google
Yahoo
Technorati
Icerocket