开发者

document.body is null or not an object [duplicate]

This question already has answers here: TypeError: document.body is null 开发者_StackOverflow社区 (2 answers) Closed 7 years ago.

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.


<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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜