Alex Rivera | Logout

Attach a body onload event with JS

Asked 2009-08-05T21:59:01.180
40

How do I attach a body onload event with JS in a cross browser way? As simple as this?

  document.body.onload = function(){
      alert("LOADED!");
  }
Edit
Report

1 Answer

25

Why not use window's own onload event ?

window.onload = function () {
      alert("LOADED!");
}

If I'm not mistaken, that is compatible across all browsers.

answered 2009-08-05T22:08:11.177

Your Answer