Forum Moderators: open
<script type="text/javascript">
function load_css(url) {
var e = document.createElement("link");
e.href = url;
e.type = "text/css";
e.rel = "stylesheet";
e.media = "screen";
document.getElementsByTagName("head")[0].appendChild(e);
}
window.onload = function( ) {
var date = new Date;
var month = date.getMonth( ) + 1;
// only run between december and february
if ((12 <= month) && (2 >= month)) {
load_css("winter.css");
}
// only run between march and may
else if ((3 <= month) && (5 >= month)) {
load_css("spring.css");
}
// only run between june and august
else if ((6 <= month) && (8 >= month)) {
load_css("summer.css");
}
// only run between september and november
else if ((9 <= month) && (11 >= month)) {
load_css("fall.css");
}
}
</script>
Any comments?
As all season are 3 months ( 1/4 of year )
var Q = Math.floor( ( month + 1 ) / 4 ) + 1;
if ( Q == 5 ) { Q = 1; } // december fudge
//
if ( Q == 1 } { load_css("winter.css"); }
else if ( Q == 2 } { load_css("spring.css"); }
else if ( Q == 3 } { load_css("summer.css"); }
else if ( Q == 4 } { load_css("fall.css"); }
<script type="text/javascript">
function load_css(url) {
var e = document.createElement("link");
e.href = url;
e.type = "text/css";
e.rel = "stylesheet";
e.media = "screen";
document.getElementsByTagName("head")[0].appendChild(e);
}
window.onload = function( ) {
var date = new Date;
var month = date.getMonth( ) + 1;
var Q = Math.floor( ( month + 1 ) / 4 ) + 1;
if ( Q == 5 ) { Q = 1; } // december fudge //
if ( Q == 1 } { load_css("winter.css"); }
else if ( Q == 2 } { load_css("spring.css"); }
else if ( Q == 3 } { load_css("summer.css"); }
else if ( Q == 4 } { load_css("fall.css"); }
}
</script>
This doesn't work, i.e., the stylesheet doesn't load (should be summer where I am). What have I overlooked, forgotten, ignored?