Jump to content

Recommended Posts

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

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>

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.

 

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>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.