Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. JavaScript: setting document.body.onload changes window.onload

JavaScript: setting document.body.onload changes window.onload

Scheduled Pinned Locked Moved Clever Code
debuggingquestioncsharpjavascriptvisual-studio
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hesham Amin
    wrote on last edited by
    #1

    I had an web page form that runs a JavaScript script function when the window loads. this was done by setting window.onload to the function name. It runs great the first time, but after the form submits it doesn't!! When I investigates the problem I found that if the IsPostBack property is true the code puts another piece of JavaScript that runs this time on the document body's onload. But why does this change stop the window.onload function ? I used VS.NET debugger to debug the script and used alert() to show the body of the window.onload handler and I found that it changes after the document.body.onload is set !!! When I returned to the documentation[^], I found that: The onload attribute of the body object sets an onload event handler for the window. This technique of calling the window onload event through the body object is overridden by any other means of invoking the window onload event, provided the handlers are in the same script language. So I had to use attachEvent method to set multiple handlers for the onload event. It's documented but I was surprised to discover this fact !!!


    Hesham A. Amin blog

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups