1

I am getting Java script error while loading page: document.body is null or not an object. URL: https://admit-uat.belgacom.be/WCE/ESW/selectBundle/productId/bun_nettv_go

Can you please let me know what is the issue.

san
  • 655
  • 2
  • 6
  • 8
  • Could you provide some sample code? – Yule Mar 24 '11 at 09:34
  • The link you posted doesn't work for me. I get a time out – Phil Hale Mar 24 '11 at 09:34
  • 2
    you should [read the Stackoverflow FAQ](http://stackoverflow.com/faq) and learn how people communicate on this site. Elaborating on your questions should not be done by adding "answers" that aren't answers. – Pointy Mar 24 '11 at 13:24

2 Answers2

3
<head>
    <script type="text/javascript" charset="utf-8">
        // wait for the DOCUMENT to become ready.
        window.onload=function(){
          walkmydog()
        }
    </script>
</head>

Here's a detailed explanation for overcoming this sort of problem: http://www.javascriptkit.com/dhtmltutors/domready.shtml

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Jack Dsilva
  • 1,504
  • 3
  • 24
  • 44
1

May be late but helpful...

You have to make sure you are calling the document.body after the <body> tag is loaded not before it.

This WILL NOT work:

<html>
     <head>
         <script>
              document.body.onload = function(){
                  alert('document Loaded');
               }
</script>

      </head>

      <body>

    </body>
</html>

This WILL work

<head>    

    </head>

    <body >        

<script>
    document.body.onload = function(){
    alert('document Loaded');
    }
    </script>

    </body>

    </html>

This also WILL work

</head>

<body onload = "function foo(){
alert('document Loaded');

   } foo();">


</body>

</html>

However, if you insist of having the Javascript before the <body> tag, You could go for jQuery's

$(function(){

//.....Your code here.
})

This is also one way to guard against cross-browser issues.

Hop that helps!

ErickBest
  • 4,586
  • 5
  • 31
  • 43