There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp 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!

 
Thread Tools
dudeking's Avatar
Computer Specs
Senior Member with 345 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,202 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 345 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,202 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.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
Pingbacks are Off
Refbacks are Off

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 10:11 PM.
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.