Can someone help me with a javascript to change the CSS according to the time of the day. So, when it is the night, the CSS would be one file. During dawn, another
Poke around Apple's iPod site... They are using an onclick function to change the CSS, so just modify this behaviour to get and check the time. An if-else should do fine.
And the code needs to be commented out so that it will not display on browsers with no scripting capabilities. You will also need a <noscript> section.
Comments
can i do this?
<script type="text/javascript">
dateObject = new Date();
theTime = dateObject.getHours();
if (theTime < 8 )
{
document.write("<link rel='stylesheet' type='text/css' href='styles-afternoon.css'>");
}
else if ((theTime > 8 ) && (theTime < 17))
{
document.write("<link rel='stylesheet' type='text/css' href='styles-night.css'>");
}
else if ((theTime > 17) && (theTime < 21))
{___
document.write("<link rel='stylesheet' type='text/css' href='styles-afternoon.css'>");
}
else
{
document.write("<link rel='stylesheet' type='text/css' href='styles-night.css'>");
}
</script>
Originally posted by Mount_my_floppy
Does your host support PHP? If so this would be a real quick script I could do up for you.
You just missed out 'var' in front of 'dateObject' and 'theTime'.
The code should look like that:
<script type="text/javascript">
var dateObject = new Date();
var theTime = dateObject.getHours();
...
Your if-else seems to contain quite a bit of unnecessary switches... But I guess you're going to do morning and stuff as well
THankles
Originally posted by Mount_my_floppy
i am doing this just on my computer here, no PHP
Originally posted by Nebagakid
i am doing this just on my computer here, no PHP
Could have told the fella earlier...
Also, please stop smoking. It's bad for you. :P
Originally posted by catalyst
Could have told the fella earlier...
Also, please stop smoking. It's bad for you. :P
oddly enough i don't smoke!!!!