Closed Thread Icon

Topic awaiting preservation: Date based CSS change (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23514" title="Pages that link to Topic awaiting preservation: Date based CSS change (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Date based CSS change <span class="small">(Page 1 of 1)</span>\

 
Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 10-01-2004 22:09

I'm looking for a script that can read the clients PC date and present my site with different CSS styles only on saturdays. Anyone, here use anything like that currently?



(Edited by Boudga on 10-01-2004 22:13)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-01-2004 22:27

If not too much has to change, the easiest way to do this might be to add a bit of javascript which detects the day of the week and, if it's saturday, adds the class "saturday" to the body element. Something like this (untested and probably flawed code):

today = new Date();
if (today.getDay() == 6) // 6 == saturday, maybe?
{
document.getElementsByTagName('body')[0].className = 'saturday';
}

Then, in your style sheet, you can simply preceed any rules that you want to apply only on saturdays with body.saturday:

p {
color:black;
}

body.saturday p {
color:red;
}

If someone doesn't have JavaScript enabled, they'll simply always see the weekday version of the site.


 

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 10-01-2004 23:06

And if you want to load another CSS you can also do :

code:
<link rel="stylesheet" type="text/css" id="myCss" href="normal.css" />
<script type="text/javascript">

if( (new Date()).getDay()==6 )
document.getElementById('myCss').href = "saturday.css"

</script>

Place that code in the HEAD. Alas, I think that on saturdays the normal.css will be loaded and replaced by the saturday.css.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 10-01-2004 23:27

If you want to use PHP, you can try something this: (untested)

code:
<?
if(date("w") == 6) $style = 'saturday';
else $style = 'weekday';
?>
<link rel="stylesheet" media="all" type="text/css" href="<? echo $style; ?>.css" />



[edit: Place code in your <head> ]



(Edited by zavaboy on 10-01-2004 23:29)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-01-2004 23:32

If you want to split the CSS up into two files, and use either poi's or zavaboy's suggestions, it might be better to provide both style sheets, one as an "alternate" style sheet, and then simply change which one is the alternate. See http://www.alistapart.com/articles/alternate/ .

This seems like a better option because you're acknowledging to your users that the site has two separate styles which it switches between. (This might have the nice side effect of letting their browser cache both in the first visit.) It might not be such a good idea if it's important to you that the user be unable to switch between the two sheets at will.


 

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 10-01-2004 23:40

zavaboy: I suppose Boudga asked a client side solution because his visitors are from various time zones, and especially another time zone than that of the server.

Of course it's possible to use a cookie to let the server know the time zone of the client, but that's a bit over-complicated.

Slime: the alternate solution is really good!

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 10-02-2004 00:18

Poi, I do agree with you and I knew he was searching for a client side solution, but I just wanted to give a alternative to client side scripting. I just felt like it anyway.

Boudga
Maniac (V) Mad Scientist

From: Jacks raging bile duct....
Insane since: Mar 2000

posted posted 10-05-2004 14:35

Thank you all for your wonderful contributions! As time permits I will look at which solution is best for my case. Currently, I'm seeking to change my client's business www site on Saturdays to the colors of my clients favorite college football team.

« BackwardsOnwards »

Show Forum Drop Down Menu