There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
 
Web Design & Development
Tag Cloud
audio bios blue screen boot bsod card computer connection crash dell drivers error excel firefox freeze freezing google hard drive hardware hijackthis install internet laptop linux malware network no sound outlook problem reboot redirect router screen server slow sound speakers spyware startup trojan usb video virus vista vundo windows windows 7 windows vista windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Javascript Cookies

Tip: Click here to scan for System Errors and Optimize PC performance
[ Sponsored Link ]

Closed Thread
 
Thread Tools
dudeking's Avatar
Computer Specs
Senior Member with 419 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,505 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 419 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,505 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 Bookmark and Share

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.

Smart Search

Find your solution!



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 want to help you solve your 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 -5. The time now is 05:46 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Powered by Cermak Technologies, Inc.