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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:28:24+00:00 2026-05-28T03:28:24+00:00

I ran across a weird error today. I had a simple userscript which was

  • 0

I ran across a weird error today. I had a simple userscript which was adding a window.onload event to all the sites. But one of the sites had a <body onload="func();"> defined. What happened is that window.onload was working as usual but <body onload=""> stopped working for the site after installing userscript.

When I used window.body.onload instead both worked well. I know that window.onload and <body onload=""> are different way of doing the same thing but what is happening in window.body.onload which makes it work well with <body onload="">?

  • 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-28T03:28:24+00:00Added an answer on May 28, 2026 at 3:28 am

    As Myforwik said, the event you hook up with window.onload = ...; is the same event you hook up with <body onload="...">. It’s the window load event. Both of those ways of hooking it are in the old DOM0 style, which has been obsolete for some time. If you specify both, the latter one will win, knocking out the former. The same is true if multiple scripts set window.onload independently.

    To avoid these sorts of issues, use DOM2-style event hookup:

    if (window.addEventListener) {
        // DOM2 standard
        window.addEventListener("load", handler, false);
    }
    else if (window.attachEvent) {
        // Microsoft's precursor to it, IE8 and earlier
        window.attachEvent("onload", handler);
    }
    else {
        // Some pre-1999 browser
        window.onload = handler;
    }
    
    function handler() {
    }
    

    Multiple DOM2 handlers can be attached to the same event, so multiple unrelated scripts can subscribe to it. Also, DOM2 handlers happily co-exist with DOM0 handlers.

    So if you update your userscript to use the above, the <body onload="..."> page will be unaffected.

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

Sidebar

Related Questions

I ran across a piece of C# code today I had not seen before.
I ran across this case of UnboundLocalError recently, which seems strange: import pprint def
I ran across a compilation issue today that baffled me. Consider these two container
I ran across an interesting issue today. We have an application that utilizes Zend
I ran across the error Socket operation on non-socket in some of my networking
I ran across this issue today and was able to determine that, when doing
I ran across a tutorial that had the following syntax: rails generate model User
i ran across something similar to the below code snippet, which throws a compiler
I ran across some code like this today; having a flow control flag that
I recently ran across some 3rd party C# code which does the following: public

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.