NameSilo

[Resolved] Changing color scheme

Spaceship Spaceship
Watch

John84

Established Member
Impact
2
Changing color scheme

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?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I think that can be done through cookies.

I cannot see any other better explanation for the site to remember the preferences of the user even if he or she visits it after some days.
 
0
•••
Problem Solved. Used the following...

Code:
<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>
 
0
•••
Dynadot — .com Registration $8.99Dynadot — .com Registration $8.99

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back