/    Sign up×
Community /Pin to ProfileBookmark

cross browser on layer.style ?

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([url]http://www.mysite.com/bg.gif[/url])’;
} 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

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@JonaMay 17.2003 — 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);"

}
Copy linkTweet thisAlerts:
@khalidali63May 17.2003 — 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..
Copy linkTweet thisAlerts:
@JonaMay 17.2003 — [b][font=arial][color=maroon]Khalid, does style.backgroundImage work in Netscape? I thought it was IE only, but I guess I should've mentioned that.[/color][/font][/b]
Copy linkTweet thisAlerts:
@khalidali63May 17.2003 — it works in all major browsers( as of today)..:-)
Copy linkTweet thisAlerts:
@JonaMay 17.2003 — [b][font=arial][color=maroon]LOL.... As of today. ?[/color][/font][/b]
Copy linkTweet thisAlerts:
@BungholioauthorMay 17.2003 — LOL, thanks guys, sorry i should have said Header was the id for the div ? .. anyways, thanks again!
×

Success!

Help @Bungholio spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...