Using Multiple JavaScript Onload Functions

 Sometimes, many functions are called after pageload (html page). It is not good if we write code directly in html, not in function, exspecially when we use back button  in IE browser.



<script> callSomeThingDirectly(); </script>



The callSomeThingDirectly() function runs before page onload, so it gets old value of the browser.

It’s better and works well if we call the functions in pageload, like this:

function func1() {
  alert(“This is the first.”);
function func2() {
  alert(“This is the second.”);

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != ‘function’) {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
addLoadEvent(function() { = ‘#EFDF95’;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: