CSSを季節ごとに切り替えているが、手作業なのでできなかったりすることもある。
自動で切り替えられたら便利だろうなぁと思って、やり方を探してみた。
4galaxyに時間で変更する方法が載っていたので、改良してみた。
これで10月になると自動的に切り替わるので、お楽しみに・・・。
といっても、PCの日付を変えれば、いつでも変わるけど・・・。
■ヘッダー内のスクリプト
function getCSS()
{
datetoday = new Date();
timenow=datetoday.getTime();
datetoday.setTime(timenow);
theMonth = datetoday.getMonth()+1;
if (theMonth == 4)
display = "css/mynotebook1.css";
else if (theMonth == 5)
display = "css/mynotebook1.css";
else if (theMonth == 6)
display = "css/mynotebook1.css";
else if (theMonth == 7)
display = "css/mynotebook2.css";
else if (theMonth == 8)
display = "css/mynotebook2.css";
else if (theMonth == 9)
display = "css/mynotebook3.css";
else if (theMonth == 10)
display = "css/mynotebook6.css";
else if (theMonth == 11)
display = "css/mynotebook7.css";
else if (theMonth == 12)
display = "css/mynotebook4.css";
else if (theMonth == 1)
display = "css/mynotebook5.css";
else if (theMonth == 2)
display = "css/mynotebook5.css";
else if (theMonth == 3)
display = "css/mynotebook5.css";
else
display = "css/mynotebook1.css";
var css = '<'; css+='link rel="stylesheet" href=' + display + ' \/'; css+='>';
document.write(css);
}
■ボディ内のスクリプト
<script language="javascript">getCSS();</script>
<noscript>
<link rel="stylesheet" href="css/mynotebook1.css" type="text/css">
</noscript>