JavaScript Call Funtion After Page Load
Written on July 22, 2008 at 11:03 am by
mkyong
Usually we can call a function during page on load with following two methods.
<body onload="happycode() ;">
or
<script> window.onload=happycode ; </script>
But how we can call a javascript function after a page load? I solved it by using a very simple method, it did exactly what i want and call after page and content loaded. Just add an onload function at the end of the body.
<html>
<script language='javascript'>
function happycode(){
alert('helo');
}
</script>
<body>
<h1>Javascript call after page loaded</h1>
<script>
//call after page loaded
window.onload=happycode ;
</script>
</body>
</html
Oracle Magazine (Free)
Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world\'s largest enterprise software company.
Publisher : Oracle Corporation



There are many better ways of doing this. You can load your site even more faster by loading JavaScript files and references after content
http://www.tutkiun.com/2010/07/load-javascript-after-pageload.html
Brilliant! Thanks Mkyong!
I work for a company that only allows me to edit blocks and won’t give me access to the website layout. I just installed a rotating image function in my block and your code activated it!
No need to set window.onload function at the end of page…
Thanks a lot friend.
Great, this would be handy if we could call out external javacript like this.
For instance instead of putting this in our head (or at the bottom of the page):
call this external sript from an onLoad.. but how?
How can I call that external scipt only to be called/loaded after the page has loaeded?
article updated with full code provided. The “happycode” is a normal javascript function, the point is call this function at the end of the body.
Please show me some sample code (more than shown above):
….
…
//call after page loaded
window.onload=happycode ;
Where and how to define happycode? also where do you call
window.onload=happycode?
wwwwwiiiiii! thanks! exactly what i need!
Very simple – thanks
ya sometime it’s just we think too much