View Single Post
Old 09-23-2012, 01:36 PM   PM User | #14
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Place the relevant code only on the pages you wish the image to appear. The Javascript should be an external file.

UTC time is not the same as London Time when daylight saving is in operation.
It would help if you indicated your country. You refer to "Labor Day" (USA) but also London GMT.

Here is another shop open/closed script:-

Code:
<html>
<head>
<style type="text/css">

#openSign.OPEN {
    color: green;
    background-color: yellow;
    font-size: x-large;
    width:350px;
}
#openSign.CLOSED {
    color : red;
    background-color: pink;
    font-size: large;
    width:350px;
}

</style>

<script type="text/javascript">

var OPENAT = 7.5; // 7:30 AM ... change as appropriate - can be fractions of an hour e.g. 7.5 = 7:30am
var CLOSEAT = 21; // 9:00 PM ... change as appropriate
var OPENATSAT = 8.75;  // 8.45 AM .. change as appropriate
var CLOSEATSAT = 13;  // 1.00 PM ... change as appropriate

function areWeOpen( ) {

var sign = document.getElementById("openSign");
var day = new Date().getDay();
var hour = new Date().getHours();
var mins = new Date().getMinutes();
hour = hour + mins/60;
if ( day >=1 && day <=5 && hour >= OPENAT && hour < CLOSEAT )  {  // Monday - Friday
sign.innerHTML = "We are now OPEN";
sign.className = "OPEN";
} 
else if ( day == 6  && hour >= OPENATSAT && hour < CLOSEATSAT )  {  // day 6 = Saturday
sign.innerHTML = "We are now OPEN";
sign.className = "OPEN";
} 
else {
sign.innerHTML = "Sorry, we are now CLOSED";
sign.className = "CLOSED";
}

}
</script>
</head>

<body onload = "areWeOpen()">
<center>
<h2>Welcome to our Store</h2>
<br/>
<h3 id="openSign"></h3>
<br/>
</center>
... rest of page ...
</body>
</html>
Obviously you can replace the text by an image.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 09-23-2012 at 01:50 PM..
Philip M is offline   Reply With Quote