|
|
|
Реагирование на время суток
<html>
<head>
<script language="JavaScript">
function getHourOfDay()
{ var now = new Date();
return(now.getHours());
}
function getTime()
{
var now = new Date();
var minutes = now.getMinutes();
var divider = ":";
if (minutes<10)
divider = ":0";
// Hack to get it to display the time
// correctly in version 3.0, (adjust
for offset)
if (navigator.appVersion.lastIndexOf('3.')
!= -1 &&
navigator.appName.lastIndexOf
('Netscape') != -1)
return( now.getHours()-1
+ divider + minutes );
// Other versions may work with this ?
return( now.getHours() + divider + minutes );
}
function sayHello ()
{
document.write( "Сейчас <B>" +
getTime() +
"</B>,
поэтому мы желаем Вам" );
if(getHourOfDay()<5 || getHourOfDay()>19)
document.write(' спокойной ночи!');
else
{
if ( getHourOfDay() < 11)
{
document.write(' доброго
утра!');
}
else
{
document.write(' хорошей
работы!');
}
}
}
</script>
</head>
<body>
<script language="JavaScript">
<!--
sayHello()
// -->
</script>
</body>
</html>
|
|
|