PDA

View Full Version : Display page depending on day/night; script anyone?



kopertone2
09-09-2008, 01:40 AM
Hey I was wondering if any one knew of a script for displaying a certain page when visiting a site depending on night or day on the local machine. I've found them for showing certain images, but I was looking for a script where a night home page or a day home page would be displayed.

Nile
09-09-2008, 02:38 AM
This should work:


<script type="text/javascript">
window.onload = function(){
var hour = new Date().getHours();
var time;
if(hour > 11){
window.location.href="http://www.example.com/night";
} else {
window.location.href="http://www.example.com/morning";
}
}
</script>

rainarts
09-09-2008, 02:50 AM
Just a quick example on how to load different pages depending to night and day!
Hope this would help you up!
If the current time is equals to 6pm, then this code will load the night page!



This should go along with your daypage.html!
Code is as follows:


<html>
<head>
<title>Day Page</title>

<script type="text/javascript">
<!--
window.onload = function()
{ var today = new Date();
var hour = today.getHours();
if ( hour >= 18 && hour <= 6 ) { window.open('somenightpage.html', target='_self', 'toolbar = yes, scrollbars = yes, location = yes'); return false; } else { return true; }
}
//-->
</script>
</head>
<body>
<p>Day Page!<
</body>
</html>