PDA

Click to See Complete Forum and Search --> : Change div and layer background in netscape 4.75 with javascript


JebeDiAH
Jun 19th, 2002, 11:08 AM
Hi there,

is there any possibility to change background-images of a div or a layer in Netscape 4.75 by means of javascript?

The problem is the following:

I manage to change the background of a layer (is it possible for divs too??) but the problem is, that I am not able to turn background-repeat = "no-repeat". This is a style - function and I put the style for the layer and for the div. But when I change the background dynamically, it seems to have no effect....:(.

What I do is the following:

I have a Java-Script file containing the following lines in one function:

document.menuImage.background.src=$img.src;

in the html - file I have declared the following layer-object:

<layer height="42" id="menuImage" style="background-repeat:no-repeat;"></layer>

the image changes properly, but the background-repeat is one.

Does someone know why? I would really be very grateful

Thx
Yours
Jeb

punkpie_uk
Jun 20th, 2002, 04:04 AM
Netscape 4 doesnt work that way. Although you can use the style attribute, it is not supported in the same way as Mozilla.

Try something like this : -


<html>
<head>
<script language="javascript" type="text/javascript">
function changeBgImage(layerID,urlName){
document.layers[layerID].bgImage=urlName;
}
</script>
</head>
<body>
<layer id="layer1" width="200" height="200" background="http://yourdomain.com/image1.jpg" onMouseOver="javascript:changeBgImage('layer1','http://yourdomain.com/image2.jpg')" onMouseOver="javascript:changeBgImage('layer1','http://yourdomain.com/image1.jpg')">
</layer>
</body>
</html>