different stylesheet in different weekdays??

Discussion in 'CSS' started by ghyper.com, Feb 15, 2010.

  1. #1
    i tried this but not working

    <script type="text/javascript">
    var now = new Date;
    var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday");
    document.write('<link rel="stylesheet" type="text/css" href="'+days[now.getDay()]+'.css" />');
    </script>
     
    ghyper.com, Feb 15, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    It has to work. And what doesn't work?
     
    s_ruben, Feb 15, 2010 IP
  3. ghyper.com

    ghyper.com Peon

    Messages:
    809
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I dont know. let me try again
     
    ghyper.com, Feb 15, 2010 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    Are there all css files (Sunday.css, Monday.css, Tuesday.css, Wednesday.css, Thursday.css, Friday.css, Saturday.css) in the root directory??
     
    s_ruben, Feb 15, 2010 IP
  5. ghyper.com

    ghyper.com Peon

    Messages:
    809
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah. everything is there but +days[now.getDay()]+ dont change into filename :(
     
    ghyper.com, Feb 15, 2010 IP
  6. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #6
    Write this script and tell me what it will alert:

    
    <script type="text/javascript"> 
    var now = new Date; 
    var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday"); 
    alert('<link rel="stylesheet" type="text/css" href="'+days[now.getDay()]+'.css" />'); 
    </script>
    
    Code (markup):
    And can you write the url of the website?
     
    s_ruben, Feb 15, 2010 IP
  7. ghyper.com

    ghyper.com Peon

    Messages:
    809
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks I tried it with if else statement and it worked for me... pasting here for people in case,if they need it

     
    ghyper.com, Feb 16, 2010 IP
  8. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #8
    Try this:

    
    <script type="text/javascript">
    var now = new Date;
    var weekdays = new Array("sun", "mon", "tue", "wed","thu", "fri", "sat");
    document.write("<link rel='stylesheet' href='{THEME}/css/"+weekdays[now.getDay()]+".css' type='text/css'>");
    </script>
    
    Code (markup):
     
    s_ruben, Feb 16, 2010 IP
  9. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #9
    I probably wouldn't be bothering to do this client side, as this is EXACTLY the type of thing that should probably be handled server side using PHP/ASP/PERL or some other scripting.

    I would actually NOT expect that to work in all browsers, as file includes cannot be dynamically written/processed last I knew.

    I would probably handle that thus:
    HTML
    
    <link
    	type="text/css"
    	rel="stylesheet"
    	href="{THEME}/css/noScriptDay.css" 
    	media="screen,projection,tv"
    	id="dayStylesheet"
    />
    
    Code (markup):
    Javascript

    
    <script type="text/javascript"><!--
    	var now=new Date;
    	var weekdays=['sun','mon','tue','wed','thu','fri','sat'];
    	document.getElementById('dayStylesheet').href='{THEME}/css/'+weekdays[now.getDay()]+'.css';
    </script>
    
    Code (markup):
    Though that assumes you are hardcode replacing {THEME} - which if that's some sort of 'skinning' system replacement is likely NOT being filled in properly. It does however mean you have a javascript off fallback in addition to the ones unique to each day; Remember the rule, javascript should enhance, not supplant. (Yes jquery ****tards, I'm looking at you)

    Do you have a demo page online we could get a URL to so we can see where it's going wrong?

    -- edit --
    Oh, and I'd consider changing those to day_0, day_1, etc so you can lose the array lookup.

    
    <script type="text/javascript"><!--
    	var now=new Date;
    	document.getElementById('dayStylesheet').href='{THEME}/css/day_'+now.getDay()+'.css';
    </script>
    
    Code (markup):
     
    deathshadow, Feb 16, 2010 IP
    ghyper.com likes this.
  10. ghyper.com

    ghyper.com Peon

    Messages:
    809
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    hehe, Thanks for you replies..

    I mentioned above that I got a solution by putting if else
    even though thats a big code but its working without any trouble
     
    ghyper.com, Feb 16, 2010 IP