Jump to content

Time sensitive


Excitus

Recommended Posts

I need the text to appear from 16:30 to 8:30 the next days.

Thats all I have worked out :( but the time is inv3erted and Im missing minutes...

 

<html>

<head>

</head>

<body>

<script>

var curdate = new Date();

if (curdate.getHours() >= 8 && curdate.getHours() < 20)

alert('You reporting after hours, please call this number 555-555-5555, then submit the incendent report');

</script>

</body>

</html>

Link to comment
Share on other sites

 

You just needed to flip some stuff around:

 

<html>
<head>
</head>
<body>
<script>
var curdate = new Date();
if (curdate.getHours() >= 8 && curdate.getHours() < 20) {
// error is not given because you are open
}
else {
alert('You reporting after hours, please call this number 555-555-5555, then submit the incendent report'); 
}
</script>
</body>
</html>

Link to comment
Share on other sites

 

try this; it may not work, but check and see:

 

<html>
<head>
</head>
<body>
<script>
var curdate = new Date();
if (curdate.getHours() >= 8.5 && curdate.getHours() < 20.5) {
// error is not given because you are open
}
else {
alert('You reporting after hours, please call this number 555-555-5555, then submit the incendent report'); 
}
</script>
</body>
</html>

Link to comment
Share on other sites

Not to burst anyone's bubble, but using JavaScript for this type of display calculation requires that you are dependent upon your client time being accurately set. JavaScript pulls the system time, so if someone has their time set to one different than yours, or if they have their timezone offset differently than yours, you'll always have it show during THEIR 16:30 - 8:30.

Link to comment
Share on other sites

The time set or time zone is not really that big of an issue.

What i'm more concerned about is, not having an alert (popup), but more as a text on the site shown between does hours?!

 

Possible??

 

 

Don't use alert(), but rather use document.write()... or even better, put a div with an id where you want your message to show and update the content. For instance, have something like this in the page: <div id="messageDiv"></div>

 

Then, you can access is like this:

document.getElementById('messageDiv').innerHTML = "My Message!!!";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.