Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Changing color scheme
Old 07-15-2007, 10:58 PM Changing color scheme
John84's Avatar
Skilled Talker

Posts: 64
Name: John
Trades: 0
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='b g_green.css'" />
<img src="images/bg_blue_box.gif" alt="" onclick="document.getElementById('bg_css').href='b g_blue.css'" />
<img src="images/bg_peach_box.gif" alt="" onclick="document.getElementById('bg_css').href='b g_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?
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
John84 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-16-2007, 10:23 AM Re: Changing color scheme
willcode4beer's Avatar
Super Moderator

Posts: 1,533
Name: Paul Davis
Location: San Francisco
Trades: 1
If you are using "pure" client side code, your best bet to make it work across pages is to set a cookie, and read it when creating the link tag.

If you have a server side language, then store the data in the user's session and generate the appropriate link tag.
__________________

Please login or register to view this content. Registration is FREE

willcode4beer is offline
Reply With Quote
View Public Profile
 
Old 07-17-2007, 01:51 PM Re: Changing color scheme
John84's Avatar
Skilled Talker

Posts: 64
Name: John
Trades: 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>
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
John84 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Changing color scheme
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.72563 seconds with 12 queries