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 912975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:28:33+00:00 2026-05-15T17:28:33+00:00

I’m using the popular addLoadEvent as follows for all my JS loading: function addLoadEvent(func)

  • 0

I’m using the popular addLoadEvent as follows for all my JS loading:

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent( locationToggle );
addLoadEvent( step1 );
addLoadEvent( step2 );
addLoadEvent( step3 );
addLoadEvent( getCounties );
addLoadEvent( mapSelection);

Everything I’ve read suggests this is a fairly bullet proof way of avoiding onload conflicts. And yet this method doesn’t appear to working any better than wrapping the functions in an anonymous window.onload function. Both methods are causing identical onload conflicts with this set of functions.

I am loading these functions from within the same file as the addLoadEvent function itself. I’m also using calender.js which is a third party file which uses mootools 1.2.4 in an additional file. My files are otherwise free of Javascript.

First, could someone verify I’ve not damaged the code and I’m using it right. Second could someone suggest why the above is not resolving the conflicts?

edit
The problem persists with all other Javascript files disabled.

  • 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-15T17:28:33+00:00Added an answer on May 15, 2026 at 5:28 pm

    Your code is fine. The problem is that setting event handlers in the DOM 0 way doesn’t ensure that they won’t replaced by other code.

    You may try the new W3C standard addEventListener and the IE version attachEvent, because the handlers you attach by them cannot be replaced by 3rd party code.

    // window.onload W3C cross-browser with a fallback
    function addLoadEvent(func) {
      if (window.addEventListener)
        window.addEventListener("load", func, false);
      else if (window.attachEvent)
        window.attachEvent("onload", func);
      else { // fallback
        var old = window.onload;
        window.onload = function() {
          if (old) old();
          func();
        };
      }
    }
    

    Note, that IE will execute the function in reversed order not in the order you added them (if this is a concern).

    Finally, I don’t know when you want to run your code, but if you don’t want to wait for images to load you can execute your functions earlier then window.onload.

    Dean Edwards has a nice script which will let you to do that.

    With this you can attach your functions for an earlier event: document.ready (DOMContentLoaded)

    // document.ready
    function addLoadEvent(func) {
      if (typeof func == "function") {
        addLoadEvent.queue.push(func);
      }
    }
    addLoadEvent.queue = [];
    
    //////////////////////////////////////////////////////////////////////////////
    
    // Dean Edwards/Matthias Miller/John Resig
    
    function init() {
      // quit if this function has already been called
      if (arguments.callee.done) return;
    
      // flag this function so we don't do the same thing twice
      arguments.callee.done = true;
    
      // kill the timer
      if (_timer) clearInterval(_timer);
    
      // do stuff: execute the queue
      var que = addLoadEvent.queue;
      var len = que.length;
      for(var i = 0; i < len; i++) {
        if (typeof que[i] == "function") {
          que[i]();
        }
      }
    };
    
    /* for Mozilla/Opera9 */
    if (document.addEventListener) {
      document.addEventListener("DOMContentLoaded", init, false);
    }
    
    /* for Internet Explorer */
    /*@cc_on @*/
    /*@if (@_win32)
      document.write("<script id=__ie_onload defer src=javascript:void(0)>"
                    +"<\/script>");
      var script = document.getElementById("__ie_onload");
      script.onreadystatechange = function() {
        if (this.readyState == "complete") {
          init(); // call the onload handler
        }
      };
    /*@end @*/
    
    /* for Safari */
    if (/WebKit/i.test(navigator.userAgent)) { // sniff
      var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
          init(); // call the onload handler
        }
      }, 10);
    }
    
    /* for other browsers */
    window.onload = init;
    

    Note: the usage is the same for both methods as it was for your version.

    ​

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

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I found what was the problem. I used addStretch() on… May 16, 2026 at 10:55 am
  • Editorial Team
    Editorial Team added an answer EDIT: I see you were the one who asked the… May 16, 2026 at 10:55 am
  • Editorial Team
    Editorial Team added an answer Use the measure() method to set your text component sizes.… May 16, 2026 at 10:55 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.