SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.bgColor doesn't work in firefox ?

    hi,

    the next script works perfectly in explorer but doesn't work ik firefox,
    It is supposed to change bgcolor of the page depending on wich menu the page belongs to.
    REPLACE_BY_MENU is replaced by the correct number.
    So the error should lie in document.bgcolor ?
    you can see the result at www.bouworde.be (dutch speaking site)

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> Bouworde vzw </TITLE>
    <META NAME="Generator" CONTENT="">
    <META NAME="Author" CONTENT="Faber Vanmolkot iov Bouworde vzw">
    <META NAME="Keywords" CONTENT=" bouwkamp, sociaalkamp, ecokamp, sensokamp, vrijwilligerswerk ">
    <META NAME="Description" CONTENT="">
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <!--vervangt bollen door tekst EN laat telkens het juiste menu zien links-->
    <script type="text/javascript">
    			//knop "zwart" maken
    			function bolIt(id){
    				document.getElementById('bol' + id ).src='layout/bol' + id + '_of.gif';// was 'images/test' + id + '_on.GIF'
    			}
    			function bolIt(id,huidig){
    				if (id!=huidig){
    				document.getElementById('bol' + id ).src='layout/bol' + id + '_of.gif';// was 'images/test' + id + '_on.GIF'
    				}
    			}
    			//knop "grijs" maken:
    			function whiteIt(id){
    				document.getElementById('bol' + id).src='layout/bol' + id + '_on.gif'; //'layout/bol' + id + '_of.gif'
    			}
    
    			function loadMenu(id) {
    				
    				bolIt(id);
    				
    				//alle menus onzichtbaar maken:
    				//for(dummy=1;dummy<=4;dummy++){
    				//	document.getElementById('menu'+dummy).style.display='None';
    				//}
    				
    				//huidige menu tonen:
    				document.getElementById('menu'+id).style.display='';
    			}
    			function unloadMenu(id) {
    				whiteIt(id);
    				//document.getElementById('menu'+id).style.display='None';
    			}
    				var geval = REPLACE_BY_MENU;
    				switch (geval) {
    				case 0: document.bgColor = '#fbc202'; break;
    				case 2: document.bgColor = '#fbc202'; break;
    				case 11: document.bgColor = '#f3983f'; break;
    				case 44: document.bgColor = '#f1abb1'; break;
    				case 52: document.bgColor = '#7e1a26'; break;
    				default: document.bgColor = '#fbc202';
    				}
    		</script>
    </HEAD>
    
    <BODY bgcolor=#f79648>

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try with document.style.backgroundColor

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try document.body.bgColor, but bgColor is obsolete.

    Use document.body.style.backgroundColor instead.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tnx for the replies but...

    document.body.style.backgroundColor doesn't work in explorer and ff .... :-(
    same for document.style.backgroundColor and document.body.bgColor
    also tried document.style.bgColor... nothing.

    Am I doing something else wrong ?
    Should I change my body tag ? Or use the style.css page ?

    djemmers

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by djemmers View Post
    document.body.style.backgroundColor doesn't work in explorer and ff .... :-(
    Works for me.

  6. #6
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh! You're running it before the page has finished loading, aren't you?

    You can't do that. You need to use a window.onload handler.
    The simplest way to do that is this:
    Code:
    window.onload = function(){
      var bstyle = document.body.style;
      switch (geval) {
        case 0: bstyle.backgroundColor = '#fbc202'; break;
        case 2: bstyle.backgroundColor = '#fbc202'; break;
        case 11: bstyle.backgroundColor = '#f3983f'; break;
        case 44: bstyle.backgroundColor = '#f1abb1'; break;
        case 52: bstyle.backgroundColor = '#7e1a26'; break;
        default: bstyle.backgroundColor = '#fbc202';
      }
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  7. #7
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do I run the code after the page finished loading ?
    put it at the bottom of the page ?
    after the </body> tag ?

    edit: works now (behind </body> tag) tnx a lot !

  8. #8
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do I run the code after the page finished loading ?
    I just told and showed you. Use the window.onload event handler.

    put it at the bottom of the page ?
    after the </body> tag ?

    edit: works now (behind </body> tag) tnx a lot !
    You put a <script> element after the </body> end tag? That isn't valid.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  9. #9
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok it is working now tnx a lot !


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •