bgColor does not work in Firefox, is there an alternative?

I tried this in my script:

newWindow.document.bgColor="#CC9900";

It does not work in FF, is there an alternative for adding color directly to the document object?

Thanks guys!

Novice

In this case you have learnt something ancient.

bgColor was the way it was done before CSS was introduced.

If you set background-color in your CSS you can’t override it using bgColour. The only way to get bgColor to work is if you use HTML 3.2 and set bgcolor= inside your HTML.

The need for bgColour should have completely disappeared by about 2004 or so and so is not something important to learn unless you need to know about it in order to know how to rewrite the code for the 21st Century.

Please, do not apologize. I am a novice, I can take a little of that.

I have a massive collection of JavaScript books. The problem is most of these books will have 12 champters deveted to theory and 1 chapter to actual practical JavaScript. LOL!!

Any, it see all other colors will work but when I try this:

#fbf3eb"; 

However this would work:

#9CF000

.

I am confused as well.

Is there another way I can add background color to the pop up window?

IC

Hmmm, I’ve never seen bgColor before. I learn something new here all the time.
I apologize if I came across seeming a bit harsh :blush:

I’m wondering if using bgColor is a “web safe color” type of thing. i.e. only works with 16,16,16 colors but not 256,256,256 colors?

You are right! This is what I have noticed, this particular color

#fbf3eb";

does not work at all.

Do you know why?

Novice

I am not guessing.

I am reading the following book:

Beginnning JavaScript 4th Edition.

By Paul Wilton and Jeremy McPeak.

Page 285, Chapter 8.

“If you wanted to change the background color of the document contained inside the new window, you would type this.”

newWindow.document.bgColor = "red";

I am trying to add a background color to a pop up window when a user click okay on the prompt box.

Here is the code, the background color changes in IE for the pop up window but not in FF.



function promptBox(){
    
     var message = prompt("Who is your favorite Hollywood Star? ", "");
     if (message == "")
     message = "Come on! That was an easy question. You should have answered it.";
     myWindow = window.open('','','width=800,height=600');
     myWindow.document.write(message);
	 myWindow.document.bgColor="#666666";
     myWindow.focus();
}

Maybe I misunderstood, not sure.

Thanks for pointing this out!

So why would this be in the book?

Novice.

Hi there Novice2010,

document.bgColor=“#CC9900 does work in Firefox and all other browsers that I tested in. :wink:

So your problem must lay elsewhere in your code.

This is my test code…

[color=navy]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>document.bgColor test</title>

<script type="text/javascript">

function init(){[color=red]
   document.bgColor='#c90';[/color]
 }

 window.addEventListener?
 window.addEventListener('load',init,false):
 window.attachEvent('onload',init);

</script>

</head>
<body>
<div></div>
</body>
</html>
[/color]

coothead

Where did you get that from? I’d be surprized if it works in any browser!

I’m guessing you’re guessing? Not always a bad thing, I do it quite often myself and its often faster than taking the time to look up the correct syntax. :wink:

Anyway try … [elem name goes here].style.backgroundColor =

The js syntax is different than the CSS, pascalCase instead of hyphens i.e.
backgroundColor instead of background-color