View Full Version : Javascript - time layout

Jan 19th, 2011, 11:18 PM
I have this code on my invisionfree forum that is suppose to change a layout from 6 AM - 6 PM but it isn't working. Here is the code

<script language="javascript">
/* script created by Chandler @ http://s4.invisionfree.com/digitalized <-- a great site for skins codes and support! */
now = new Date();
itime = now.getHours();
function TSkinChange() {

if (itime >= 19) {
document.write('<LINK REL="stylesheet" TYPE="text/css" HREF="http://hatchingyourdragons.com/daynocturne.css">');
if (itime <= 6) {
document.write('<LINK REL="stylesheet" TYPE="text/css" HREF="http://hatchingyourdragons.com/nightnocturne.css">');


Thanks in advance :)

Old Pedant
Jan 19th, 2011, 11:26 PM
<script language="javascript">
var hr = (new Date()).getHours();
var dn = ( hr < 6 || hr >= 18 ) ? 'night' : 'day';
'<link rel="stylesheet" type="text/css" '
+ ' ref="http://hatchingyourdragons.com/' + dn + 'nocturne.css">'


Jan 19th, 2011, 11:27 PM
No, that didn't seem to work. It's still showing the incorrect layout.

Apparently with this forum it isn't recognizing this script.... it's going off of the default css :/

Old Pedant
Jan 19th, 2011, 11:42 PM
I can't make the styles work even statically. Can you give an example of at least the page header using the logo image?

Jan 19th, 2011, 11:45 PM
I'm not sure, lol.... I don't mean to sound air headed but I'm not familiar with this forum type as I just started using it. Most of the html is hidden. Not sure where I can find it :confused:

Old Pedant
Jan 20th, 2011, 12:00 AM
I mean, what happens if you replace the <script> with just the <link>, hard coded???

Choosing one or the other of the css files?

Can you show that somewhere?

Jan 20th, 2011, 12:13 AM
this forum does that automatically. In the admin panel there is a place to manage your css. It doesn't show where the <link css> file is at. But if I remove that and just use the JS it doesn't have any sort of layout.

Old Pedant
Jan 20th, 2011, 12:23 AM
Okay, so replace the JS code with just a link.

Replace *all* that JS code you showed in first post with

<LINK REL="stylesheet" TYPE="text/css" HREF="http://hatchingyourdragons.com/daynocturne.css">

Does that work?

If not, then of course you can't make the JS version work.

Jan 20th, 2011, 12:33 AM
Yes that works... I had to use nightnocturne.css b.c the other is the default so I wouldn't have been able to tell

Old Pedant
Jan 20th, 2011, 12:37 AM
Had an idea: This is for a forum, right? So is this on a PHP page, perhaps? If so, do this in PHP (choose the right CSS). Then that will surely work.

Jan 20th, 2011, 12:39 AM
i don't think you can use php on this forum :(

Old Pedant
Jan 20th, 2011, 12:43 AM
??? You mean you don't control the forum??

That's weird.

I dunno. I'll have to play with it. Maybe somebody else has ideas.