Hello
I need a javascript what I can load different javascripts, depending on time of day. Is something feasible?
Greetz
Hello
I need a javascript what I can load different javascripts, depending on time of day. Is something feasible?
Greetz
24 hours a day, 24 scripts naming jsCode:<script type="text/javascript"> var date=new Date(), sScript='<script type="text/javascript" src="js'+date.getHours()+'.js"><\/script>'; alert(sScript); // Created script </script>[1-24].js.
If it's 9am, then script will be js9.js
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
Marquis (10-24-2008)
Hello
Thank you very much!
How can I do this with only 4 predefined times? 00.00 - 6.00, 6.00 - 12.00 , 12.00 - 18.00, 18.00 - 24. 00
thx
First shift (12am - 6am): jsfirst.jsCode:<script type="text/javascript"> var date=new Date(), hrs=date.getHours(),js='',sScript=''; // If 12am-6am - source equates to "jsfirst.js" // If 7am-12pm - source equates to "jssecond.js" // If 12pm-6pm - source equates to "jsthird.js" // If it's 6pm and beyond, but don't reach 12am, then source equates to "jsfourth.js" js=(hrs>=0&&hrs<=6)?'first':(hrs>6&&hrs<=12)?'second':(hrs>12&&hrs<=18)?'third':'fourth'; sScript='<script type="text/javascript" src="js'+js+'.js"><\/script>'; alert(sScript); // Created script </script>
Second Shift (7am - 12): jssecond.js
Third Shift (12-6pm): jsthird.js
Last Shift (6pm-11pm): jsfourth.js
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
Hi
Hmmm I can't get it to work. Maybe I didn't understand it right. I get only the alert, no javascript is loaded.
Can you help pls?
Greetz
Yes, the script only alerts the created test file.
If you want to create, change this part:
into:Code:sScript='<script type="text/javascript" src="js'+js+'.js"><\/script>'; alert(sScript); // Created script
Hope that helps.Code:var script=document.createElement('script'); script.type='text/javascript'; script.setAttribute('src','js'+js+'.js'); document.getElementsByTagName('head')[0].appendChild(script);
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
Maynard (10-28-2008)
Hi, thx for your reply
Now the script loads allways the jsfirst.js, no matter what time it is.
sry, i need more help.
Thx
It's working fine at my end, ensure to refresh your page right after you change your time.
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
Hi
Yes, now it works! Just a last question: If i want to have the included scripts in sub directory, "scripts" where i must change the code?
Thx very much
Add highlighted on this part:
Code:script.setAttribute('src','scripts/js'+js+'.js');
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
Bookmarks