meomike2000 Posted January 14, 2010 Share Posted January 14, 2010 i need to find a way to unset the background color. that said i have a script that does just that fine in firefox. you can set a background image, or you can set a background color and hide the background image. the problem is when i try to show the background image again. this works fine in firefox, i use this; background.style.color = ' '; i tried making the seting to transparent as well..... this dont work in Internet Explorer, i find that after setting body.style.background = 'what ever color'; , i need to remove this body attribute but cant seem to find a way. can anybody help..... thanks in advance mike..... Link to comment https://forums.phpfreaks.com/topic/188423-help-removing-bodystylebackground/ Share on other sites More sharing options...
RichardRotterdam Posted January 14, 2010 Share Posted January 14, 2010 What's the complete code you use to set/unset the background color and wich version of ie do you mean? ie 7 and lower has a few issues with the style attribut. Link to comment https://forums.phpfreaks.com/topic/188423-help-removing-bodystylebackground/#findComment-994805 Share on other sites More sharing options...
Psycho Posted January 14, 2010 Share Posted January 14, 2010 I don't think "background" is a standard object. You should be using "document.body.style.backgroundColor" and to reset the value you would use a null string not a string with a space. This test page works fine for me in IE and FF <html> <head> <script type="text/javascript"> function setBackgroundColor(color) { document.body.style.backgroundColor = color; return; } </script> </head> <body> <button onclick="setBackgroundColor('#0000ff')">Blue</button><br /> <button onclick="setBackgroundColor('#ff0000')">Red</button><br /> <button onclick="setBackgroundColor('#00ff00')">Green</button><br /> <button onclick="setBackgroundColor('')">Reset</button><br /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/188423-help-removing-bodystylebackground/#findComment-994947 Share on other sites More sharing options...
meomike2000 Posted January 14, 2010 Author Share Posted January 14, 2010 i have set var body = document.getElementById('body'); that is why i refer to it as body.... i have tried this as well body.sytle.background = null; and that fails as well..... the problem is not setting or changing the background color, the problem is i let user choose to set a background color or a background image. both work fine except that after if a uset sets a background color then tries to set a background image it will not show the image, just the set color or just a white background. if the image is set or set before a color all is good. this problem only exist in ie...... thanks mike. Link to comment https://forums.phpfreaks.com/topic/188423-help-removing-bodystylebackground/#findComment-995171 Share on other sites More sharing options...
Psycho Posted January 14, 2010 Share Posted January 14, 2010 This works for me <html> <head> <script type="text/javascript"> function setBackgroundColor(color) { //remove current background setting document.body.style.background = ''; document.body.style.backgroundColor = color; return; } function setBackgroundImage(imageURL) { //remove current background setting document.body.style.background = ''; document.body.style.background = "url("+imageURL+")" return; } </script> </head> <body> <button onclick="setBackgroundColor('#0000ff')">Blue Backgrouond</button><br /> <button onclick="setBackgroundColor('#ff0000')">Red Backgrouond</button><br /> <button onclick="setBackgroundColor('#00ff00')">Green Backgrouond</button><br /> <button onclick="setBackgroundImage('image1.jpg')">Image 1 Background</button><br /> <button onclick="setBackgroundImage('image2.jpg')">Image 2 Background</button><br /> <button onclick="setBackgroundColor('')">Reset</button><br /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/188423-help-removing-bodystylebackground/#findComment-995188 Share on other sites More sharing options...
meomike2000 Posted January 15, 2010 Author Share Posted January 15, 2010 ok fixed, thanks for the help..... the problem was when i was setting the background color i was doing it like this.... body.style.background = color; that was the problem.... should have been body.style.backgroundColor...... that works... thanks mike. Link to comment https://forums.phpfreaks.com/topic/188423-help-removing-bodystylebackground/#findComment-995394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.