Skip to content

document.body.onload fix for IE

If you are reading this, you are probably having problems with “document.body.onload” in your IE javascript code. I have had this problem a few days back and a Google search solved it.

To fix it, just change your code from:

document.body.onload = alert("Hello world");


document.onload = alert("Hello world");

It appears that document.body.onload does not work on IE. Before, when I loaded the page, I used to get  the error dialog “A Runtime Error has occured” saying “Error: Not implemented“. On debug in Visual Studio, I’d get “htmlfile: Not implemented“. All these error messages are not very clear, but fortunately, the faulty line of code was highlighted.

I have not yet researched about the difference(s) between document.body.onload and document.onload in Firefox (or IE), but if you’re only using a small piece of javascript code, you should be alright with this fix.

Published inCoding
  • thanks mate – this helped!

  • Hey Jevin, I was hoping and praying that this was the problem with my site (as usual) not working in EXPLORER (and crApple mobile browsers, but not exactly. For some reason, I still think the problem lies in this ‘document’ command. I am a graphic designer and have some limited website knowledge, but obviously, not enough.

    Can you PLEASE assist me? i am losing clients due to most using Explorer.

    Thx man,