document.body undefined in netscape

admin

Administrator
Staff member
I have a feeling that this question has been asked before, but I couldn't find it through a search. My problem is that I'm trying to change the background image for the body in ns4. I keep getting a "document.body has no properties" error. I've tried just "alert(document.body)" and gives me 'undefined'. Is it even possible to access the body with javascript in NS? I can't imagine it's not, but for some reason I can't do it. Here's my test script:<br />
<br />
<html><br />
<head><br />
<title>Untitled</title><br />
<br />
<script language="javascript"><br />
function init()<br />
{<br />
alert(document.body);<br />
}<br />
</script><br />
<br />
</head><br />
<body onload="init()"><br />
test<br />
</body><br />
</html><!--content-->If the background is already an image, why not just swap it for a new one.<!--content-->that's what I'm trying to do, but I keep getting a document.body has no properties error. <br />
<br />
document.body.background, right?<!--content--><html> <br />
<head> <br />
<title>Untitled</title> <br />
</head> <br />
<body background="THE.GIF"> <br />
test <br />
</body> <br />
Just change the present image for your image.(gif or jpg)<br />
<br />
Another way:<br />
<style type="text/css"><br />
<Body background -image;url (images\background.gif);<br />
</style><br />
<br />
(The URL is the image name and where it is located)<br />
There probably is a Script way of doing it, but I would use the first one..<!--content-->Originally posted by bisqui <br />
I'm trying to change the background image for the body in ns4.In NS 4, you cannot script anything that is not a layer, image or form. In other words, not the body. I have tried a few things, but none of them worked the way you would think they would. I have managed to change the source in the stylesheet array, but that has to be done before the body is rendered (not what you wanted).<br />
<br />
In DOM-compliant browsers (NS 6, 7, Mozilla, IE 5, 6), the DOM way to get to the body would be<br />
<br />
docBody = document.getElementsByTagName("BODY")[0];<!--content-->If you want to change the background image before the page loads, here is an example for NS 4:<br />
<br />
<head><br />
<style type="text/css"><br />
BODY {background: url(picture1.jpg) no-repeat}<br />
</style><br />
<script><br />
function changeIt() {<br />
if (document.layers)<br />
{document.tags["BODY"].backgroundImage = "url(picture2.jpg)";}<br />
else<br />
{document.body.style.backgroundImage = "url(picture2.jpg)";}<br />
}<br />
changeIt();<br />
</script><br />
</head><br />
<body><br />
<table width=100% height=100%><br />
<tr><td>Hello, I'm Mr. Ed!</td></tr><br />
</table><br />
</body><!--content-->actually, that works perfectly for what I'm doing. Just can't load the image for IE before the body loads or else it throws a missing object error. I'm just loading it for IE via onload. Thanks for the help!<!--content-->
 
Back
Top