PDA

View Full Version : style.backgroundImage not working in IE



stalkio
04-14-2010, 11:51 PM
still very new to Java but I'm trying to get the background image to change when clicknig a link and this code work in all browsers but IE. I have tried the suggestions that worked for you regards ;'s, any help would be awesome.

var backImage = new Array();

backImage[0] = "url(images/bg1.jpg)";
backImage[1] = "url(images/bg2.jpg)";
backImage[2] = "";

function changeBGImage(whichImage){

document.body.style.backgroundImage = backImage[whichImage];
}

//-->
</script>
<a href="javascript:changeBGImage(1)">Change</a>


Cheers,

Stalkio

stalkio
04-16-2010, 03:10 AM
Got this working, please find the correct code below. Also please note that IE seems to not like large files for backgrounds? very annoying when other browsers don't have issues. Hope this helps.

<script type="text/javascript">
function changeStyleOak()
{
document.body.style.backgroundImage="url(images/backgrounds/natural.jpg)";
}

</script>
.
.
.
.
<input type="button" onclick="changeStyleOak()" style="background-image:url(images/backgrounds/natural_oak.jpg);" />