SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2004
    Location
    Maryland
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Making a style sheet automatically change by season/date

    Does anyone know a javascript or other way to have your style sheets change automatically upon a certain date or season.

    I've seen "switchers" that work with manual buttons, and I've seen scripts that can change page backgrounds based on months or seasons, but I cannot find a way to do style sheets automatically.

    WARNING: I'm not a javascript writer/developer. My forte lies in HTML and CSS.

    Any help is greatly appreciated.

  2. #2
    SitePoint Enthusiast craigv's Avatar
    Join Date
    Dec 2003
    Location
    minneapolis, mn
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think that a good solution would be do use server-side code to do this. Either ASP or PHP could easily evaluate the date and dish out the desired stylesheet.

    Is your server running ASP or PHP?

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,556
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    Hi,

    As craigv said serverside is more reliable, however you could try something like this.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
    <html> 
    <head>
    <title></title>
    <script type="text/javascript"> 
    <!-- 
    today = new Date(); 
    month = today.getMonth(); 
    armonth = new Array("january.css", "february.css", "march.css", "april.css", "may.css", "june.css", "july.css","august.css", "september.css", "october.css", "november.css", "december.css"); 
    alert (armonth[month]);
    document.write("<link href=" + armonth[month] + " rel='stylesheet' type='text/css' />"); 
    //--> 
    </script>
    </head> 
    <body> 
    </body> 
    </html>
    I'll admit now that I'm rubbish at javascript but this seems to work. (No doubt everyone will tell me why it shouldn't or doesn't work.)

    Obviously you will need a noscript tag for for those that don't understand javascript or perhaps a default stylesheet that can be overwritten.

    I'm not sure the above will be a very friendly way to do it. I suppose you could use one of the proper javascript styleswitchers and just bolt the month thing on to it. So instead of being selected by a user as per a normal javascript changer the routine just passes the month across automatically.

    I'm getting out of my depth now so I'll stop (I'm strictly a CSS man).

    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •