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>
Are there all css files (Sunday.css, Monday.css, Tuesday.css, Wednesday.css, Thursday.css, Friday.css, Saturday.css) in the root directory??
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?
thanks I tried it with if else statement and it worked for me... pasting here for people in case,if they need it
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):
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):
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