document.body is null or not an object [duplicate]
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!
精彩评论