Click to See Complete Forum and Search --> : cross browser on layer.style ?


Bungholio
05-17-2003, 11:38 AM
hi, just wondering if someone can help me make a more cross-browser version of this script. (i dont need NN4 support)

if( myWidth > 900 ) {
header.style.background = 'url(http://www.mysite.com/bg.gif)';
} else {
header.style.background = 'black';
}

im guessing its something like this, but i dont really know what to put in document.layers, and what to put in document.all...?

if (document.layers) {

}else {
if (document.all) {

}
}


thanks for any help! Al

Jona
05-17-2003, 11:45 AM
Assuming "header" is the ID of some type of element, probably a DIV or SPAN tag...

if(document.layers){
document.layers["header"].document.style.background = "url(http://site.com/bg.gif);"
}
else if(document.all){
document.all["header"].style.background = "url(http://site.com/bg.gif);"
}
else { //if(document.getElementById&&!document.all){
document.getElementById("header").style.background = "url(http://site.com/bg.gif);"
}

khalidali63
05-17-2003, 11:58 AM
presuming that
"header" is an id attributes value for an element
you cando it this way
document.getElementById("header").style.backgroundImage = 'url(http://www.mysite.com/bg.gif)';
document.getElementById("header").style.backgroundRepeat = "no-repeat";

or repeat if you want..

Jona
05-17-2003, 12:00 PM
Khalid, does style.backgroundImage work in Netscape? I thought it was IE only, but I guess I should've mentioned that.

khalidali63
05-17-2003, 12:02 PM
it works in all major browsers( as of today)..:-)

Jona
05-17-2003, 12:05 PM
LOL.... As of today. :D

Bungholio
05-17-2003, 12:38 PM
LOL, thanks guys, sorry i should have said Header was the id for the div :D .. anyways, thanks again!