Welcome to WebmasterWorld Guest from 23.22.46.195

Forum Moderators: not2easy

Changing style sheets?

for color changes

   
4:36 pm on Nov 13, 2002 (gmt 0)

10+ Year Member



I want to allow the viewer to change the background and text color. There are tutorials on how to do this in javascript with alternate style sheets but I would prefer to use php can't find any info on it.

Below is from the source of a site doing what I want

<link rel='stylesheet' type='text/css' href='/themes/orange/css-orange.css'>

<a href="index.php?theme=blue" onMouseOver="(window.status='Blue theme'); return true"></a>

Is there a script for this? If so, I can't find it.

4:44 pm on Nov 13, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The trick (or one of) is to carry a variable saying which sheet to use in a Session [php.net] which can be changed be links like you've given above.

<a href="blah.php?sheet=black">blah</a>

Then on each page you need to check $_GET['sheet']
and set the sheet like this:
$stylesheet=$sheet.".css";
then plonk the little fella in your html....

Nick

5:57 pm on Nov 13, 2002 (gmt 0)

10+ Year Member



As of right now the only page using this would be the index page and should use the main sheet every time they revisit the page and have to change it per visit.

Or is that not how it works?

6:00 pm on Nov 13, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



How do you want it to work?

Nick

6:18 pm on Nov 13, 2002 (gmt 0)

10+ Year Member



I really don't know what I'm doing. I just started looking into this yesterday.

I wasn't sure if what you said before would be exactly what I needed, but it may be I really don't know.

I just want them to be able to click on the word black and change the background to black and the text to white, but the next time they visit my site if they want to see the black background again they would have to click on black again.

I don't know much about php and thought that there might be a copy and paste script to put in the html and then just add similar links like in my first message here.

6:21 pm on Nov 13, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Not that I know of....

Why would you want them to have to choose black again? -- A cookie that stores their preference might be nicer..

Admitedly I've not done this on a site I do similarly on but, it's on the TODO list ;)

Nick

6:29 pm on Nov 13, 2002 (gmt 0)

10+ Year Member



I would be nice to save it in a cookie but to be honest it looks kind of tricky to accomplish especially since I've never done it before and seems to require a lot of information that I don't already know.

Thats why I was trying to find the easiest route possible.

6:56 pm on Nov 13, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member




[pre]
<?
if(!$sheet) {
$sheet="defualt"; // no cookie - get the default
}
setcookie("sheet", $sheet, time()+30412800); // set/reset cookie for a year

$stylesheet=$sheet."css"; // set stylesheet
?>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="<?=$stylesheet;?>" />
</head>
etc...etc...
[/pre]

Untested, not properly thought out and likely not to work ;) But, may help get you started...

Nick

7:02 pm on Nov 13, 2002 (gmt 0)

10+ Year Member



Thanks I will try it, even if that doesn't work it will still be helpful in figuring out how it works as an example.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month