Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 626329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:24:26+00:00 2026-05-13T19:24:26+00:00

recently I came up with the following problem: In my web site in all

  • 0

recently I came up with the following problem:

In my web site in all html pages I call a function in body onLoad event:

<body onLoad="func1();">

This is part of my template for html, so it appears on every page in my site and I can’t change that. Now, the deal is that on some pages, I need to call some other functions onload and I tried with window.onload property, but it wipes the calling of func1…

I now that I can just say:

window.onload = func2(); //where func2() calls to func1()

but this seems dirty and lame? Isn’t it ?

So, is there a way to add some functions to those that are about to be executed onload, without deleting the old one? In addition I use asp.net if that could help …

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:24:26+00:00Added an answer on May 13, 2026 at 7:24 pm

    You can use jQuery to chain on load handlers. Repeatedly using jQuery.load or jQuery(document).ready will chain your handlers (I believe). You other option is to do it programmatically, which means you need an auxiliary function that will chain your onload handlers for you. You can do this with a closure (or anonymous function):

    var addOnLoadHandler = function(newHandler) {
    
        if (typeof window.onload != 'function') {
            window.onload = newHandler;
        }
    
        else {
            var oldHandler = window.onload;
            window.onload = function() {
                if (oldHandler) {
                    oldHandler();
                }
                newHandler();
            };
        }
    };
    

    You will have to bind your functions programmatically though, so you would have to do:

    addOnLoadHandlers(function() {
     alert("Hi I am the first onLoad handler!");
    });
    
    addOnLoadHandlers(function() {
     alert("Hi I am the second onLoad handler!");
    });
    

    in a javascript file (or in your html file).

    Another approach is to use an array:

    var onloaders = new Array();
    
    function runOnLoads() {
        for (i = 0; i < onloaders.length; i++) {
            try {
                var handler = onloaders[i];
                handler();
            } catch(error) {
                alert(error.message);
            }
        }
    }
    
    function addLoader(obj) {
        onloaders[onloaders.length] = obj;
    }
    

    In your HTML or Javascript file you do:

    addLoader(function() {
     alert("Hi I am the first onLoad handler!");
    });
    
    addLoader(function() {
     alert("Hi I am the second onLoad handler!");
    });
    

    Then in your html you can just do <body onload="runOnLoads()">

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently came across this web page http://www.yoda.arachsys.com/csharp/readbinary.html explaining what precautions to take when
Recently I came across the following snippet, which is an attempt to ensure all
I recently came across the following piece of code. It doesn't look valid because
I recently had to debug a MachO binary and I came across the following
Recently, I was buzzed by the following problem STL std::string class causes crashes and
I recently made some changes to my development environment and came across a problem.
Recently I came across with the following quiz. Imagine we have this table +--------+
I recently ran into a problem caused by using fstream::eof(). I read the following
I recently starting to play with haskell and I came across a problem while
I recently came across following syntax of Entity Framework. Notice the where clause -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.