
Originally Posted by
Raffles
What server-side language are you using? Do it with that. I suppose this would be a way to do it with javascript, but again, this would be best done on the server side.
Code:
window.onload = function() {
var date = new Date();
var hour = date.getHours();
var i;
if (hour <= 8) i = 1;
else if (hour <= 13) i = 2;
else if (hour <= 19) i = 3;
else if (hour <= 23) i = 4;
else i = 1;
body.style.backgroundImage = 'url(back'+i+'.jpg)';
}
I tried to do it on my computer in FrontPage, but its not working.
no error messages, and no reaction from the script.
I tried to put it in the header and body.
Like this:
PHP Code:
<head>
<meta http-equiv="Content-Language" content="pt">
</head>
<body>
<p>hgfhgfhfhgfhfg</p>
<script language="Javascript" type="text/javascript">
<!--
window.onload = function() {
var date = new Date();
var hour = date.getHours();
var i;
if (hour <= 8) i = 1;
else if (hour <= 13) i = 2;
else if (hour <= 19) i = 3;
else if (hour <= 23) i = 4;
else i = 1;
body.style.backgroundImage = 'url(back'+i+'.jpg)';
}
//-->
</script>
</body>
PHP Code:
<head>
<meta http-equiv="Content-Language" content="pt">
<script language="Javascript" type="text/javascript">
<!--
window.onload = function() {
var date = new Date();
var hour = date.getHours();
var i;
if (hour <= 8) i = 1;
else if (hour <= 13) i = 2;
else if (hour <= 19) i = 3;
else if (hour <= 23) i = 4;
else i = 1;
body.style.backgroundImage = 'url(back'+i+'.jpg)';
}
//-->
</script>
</head>
<body>
<p>hgfhgfhfhgfhfg</p>
</body>
The image files exist in the same folder as the script.
Bookmarks