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

  • Home
  • SEARCH
  • 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 4021332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:20:19+00:00 2026-05-20T10:20:19+00:00

I have a HTML page and a javascript function is attached to the <body>

  • 0

I have a HTML page and a javascript function is attached to the <body> onLoad event.

I wanted to show up a message dialog when the page loads. I cannot edit the javascript function attached to this onLoad event due to some reasons.

So I created a new javascript file with a single function which will show the message dialog. Then I added this line in my javascript file

window.onload = onPageLoad; 

onPageLoad() is my function which could show the message dialog.

I attached this javascript file in my HTML using script tag. When I run this HTML file, onPageLoad() function is not getting called.

I want to know whether <body> tag, onLoad event overrides the window onload. If so, can someone help me in implementing this functionality somehow.

Please keep in mind that I could not edit my HTML file and I could write only new javascript file. 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-20T10:20:19+00:00Added an answer on May 20, 2026 at 10:20 am

    Depends on browser. window.onload currently overwrites body onload in Chrome, Firefox and Safari on OSX

    You can ADD your function to the onload:

    window.onload = function() {
      alert('window.onload')
    }
    
    if (window.addEventListener) {
      window.addEventListener('load', function() {
        alert('addEventListener')
      }, false);
    } else if (window.attachEvent) { // IE < 9
      window.attachEvent('onload', function() {
        alert('attachEvent')
      });
    }
    <body onload="alert('body onload')">
    
    </body>

    AND/OR Replace

    var bodyOnload = document.body.onload;
    window.onload = function() {
      alert('window.onload')
      bodyOnload()
    }
    
    if (window.addEventListener) {
      window.addEventListener('load', function() {
        alert('addEventListener')
      }, false);
    } else if (window.attachEvent) { // IE < 9
      window.attachEvent('onload', function() {
        alert('attachEvent')
      });
    }
    <body onload="alert('body onload')">
    
    </body>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following HTML page: <html> <head> <script type=text/javascript src=JavaScript/Menu.js></script> </head> <body> <ul>
I have a HTML page that contains a flash file and some a JavaScript
I have a html page with 2 buttons on it and a big javascript
I created an index.html page that have 3 different tabs. With the function tabs()
I have an HTML page (say welcome.html) which contains an iframe to a page
I have a HTML page that scrolls up and down (not a lot, but
I have a HTML page with which I want to do some client side
We have an HTML page which displays a bunch of pretty bars using divs
Suppose I have one html page with frames. The left frame is simply a
Setup: I have an HTML page with a fieldset element. The background color of

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.