Changing color scheme

Discussion in 'Programming' started by John84, Jul 15, 2007.

  1. #1
    Im using the following code to change the color scheme of a website...

    <img src="images/bg_green_box.gif" alt="" onclick="document.getElementById('bg_css').href='bg_green.css'" />
    <img src="images/bg_blue_box.gif" alt="" onclick="document.getElementById('bg_css').href='bg_blue.css'" />
    <img src="images/bg_peach_box.gif" alt="" onclick="document.getElementById('bg_css').href='bg_peach.css'" />


    ...with this between the head tags...

    <link id="bg_css" rel="stylesheet" href="bg_green.css" type="text/css" />


    ... problem is the default color scheme, bg_green.css, will be loaded again once the user clicks on another page of the website. Is there a way for the site to remember which scheme was chosen as the user navigates through the site?
     
    John84, Jul 15, 2007 IP
  2. technoguy

    technoguy Notable Member

    Messages:
    4,369
    Likes Received:
    306
    Best Answers:
    0
    Trophy Points:
    205
    #2
    I think you have to modify css for that. If yo modify css you can change scheme of all the pages.
     
    technoguy, Jul 15, 2007 IP
  3. John84

    John84 Active Member

    Messages:
    1,288
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    80
    #3
    im giving the user the option to change the color scheme. problem is the color scheme goes back to default when user clicks to another page.
     
    John84, Jul 15, 2007 IP
  4. Da_Purr

    Da_Purr Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just make a script that sets a cookie with the colorname in it. Then make a script that reads the cookie and adjusts the page according to the color set in the cookie ;)
     
    Da_Purr, Jul 17, 2007 IP
  5. John84

    John84 Active Member

    Messages:
    1,288
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Problem Solved. Used the following...

    
    <script type="text/javascript">
    //<![CDATA[
    
    window.onload = function(){
        if(document.cookie.match(/UseCss=(\w+)/) != null){
            document.getElementById('bg_css').href = 'bg'+RegExp.$1+'.css';
        }
        else{
            document.getElementById('bg_css').href = 'bg_green.css';
        }
    }
    
    function ChangeCss(toWhich){
        document.cookie = 'UseCss='+toWhich+';';
        document.getElementById('bg_css').href = 'bg'+toWhich+'.css';
    }
    
    //]]>
    </script>
    
    Code (markup):
     
    John84, Jul 17, 2007 IP
  6. MasterOfLogic

    MasterOfLogic Well-Known Member

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #6
    i do that on this website: www homeindustry com.

    i dynamically load CSS sheets for the main page based on a user cookie that I set when they make their selection. there is a default in the event that there is no cookie. then yes, you can call this cookie from any page where needed.
     
    MasterOfLogic, Jul 17, 2007 IP