There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot bsod computer connection crash css dell display driver drivers email error explorer firefox firefox 3 hard drive internet internet explorer itunes laptop lcd malware monitor network networking outlook outlook 2003 outlook express printer problem problems ram router security slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Javascript Cookies


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
dudeking's Avatar
Computer Specs
Senior Member with 352 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
12-Jul-2007, 08:21 AM #1
Javascript Cookies
This is a script to change the theme of my site. But unfortunately it dosnt work.....

PHP Code:
<?php
            
if(isset($_COOKIE["colorscheme"])){
                if(
$_COOKIE["colorscheme"] == "black"){
                    echo 
'<link href="/style/black.css" rel="stylesheet" type="text/css" />';
                }elseif(
$_COOKIE["colorscheme"] == "white"){
                    echo 
'<link href="/style/black.css" rel="stylesheet" type="text/css" />';
                }
            }else{
                echo 
'<link href="/style/black.css" rel="stylesheet" type="text/css" />';
            }
            echo 
'<link href="/style/all.css" rel="stylesheet" type="text/css" />';
        
?>
Code:
<script type="text/javascript">
			//Colour Scheme Cookie Set
			function setcolorscheme(){
				sitetheme = getCookie(colorscheme){
					if(sitetheme == black){
						function setCookie(colorscheme,white,expiredays){
							var exdate=new Date()
							exdate.setDate(exdate.getDate()+expiredays)
							document.cookie=colorscheme+ "=" +escape(value)+
							((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
						}
					}
					if(sitetheme == white){
						function setCookie(colorscheme,black,expiredays){
							var exdate=new Date()
							exdate.setDate(exdate.getDate()+expiredays)
							document.cookie=colorscheme+ "=" +escape(value)+
							((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
						}
					}
				}
			}
		</script>
HTML Code:
<a onclick="setcolorscheme()" style="width:50px; height:50px; display:block;" href="#"> </a>

Edit:

http://dudeking.co.uk its set to the button in the top right which says white and has a down arrow
__________________
Thanks, Eddie
www.dudeking.co.uk
yankees26an's Avatar
Computer Specs
Member with 50 posts.
 
Join Date: Mar 2007
Location: NY
Experience: Newton
12-Jul-2007, 12:51 PM #2
Can you explain the problem a little bit more? What error do you get, if any?

Is the white and black cookie supposed to link to the same stylesheet, because your code loads black.css on all instances

PHP Code:
if($_COOKIE["colorscheme"] == "black"){
                    echo 
'<link href="/style/black.css" rel="stylesheet" type="text/css" />';
                }elseif(
$_COOKIE["colorscheme"] == "white"){
                    echo 
'<link href="/style/black.css" rel="stylesheet" type="text/css" />';
                }
            }else{
                echo 
'<link href="/style/black.css" rel="stylesheet" type="text/css" />'
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
12-Jul-2007, 01:10 PM #3
I could point out the errors in your code but the way you are doing things aren't that smart.

How does the php code get executed? The setcolorscheme() function doesn't refresh the page.
dudeking's Avatar
Computer Specs
Senior Member with 352 posts.
 
Join Date: Feb 2007
Location: UK, Midlands
Experience: I'm Pro...
12-Jul-2007, 02:10 PM #4
Well basicly nothing happens, no cookie is set and the style sheet doesnt change.

Thank you for pointing out that both stylesheets are the same. I'll change that now!

Well, I have never really done any Javascript before espicly nothing this advanced. I have just presumed much of the syntax to be the same as php which is wrong. Should I use all javascript or should I some how make that function refresh the page?
__________________
Thanks, Eddie
www.dudeking.co.uk
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
12-Jul-2007, 02:57 PM #5
http://www.faqts.com/knowledge_base/...d/2147/fid/128

Play with that. If you need help post back.

EDIT:

I found a function that works with IE but not with FF:

document.styleSheets[0].href = "./styles/newstyle.css";

Last edited by MMJ : 12-Jul-2007 03:25 PM.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:51 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.