javascript to refresh a web page during work hours

javascript to reset html page during work hours.

I have this (cited from another post on Experts-Exchange) but it does nothing.

<script type="text/javascript">
//60000 milliseconds is 1 minute
window.setInterval("checkForRefresh()", 600);

function checkForRefresh() {
   var now = new Date();
   if (now.getHours() >= 7) {
    window.refresh();
   }
}
</script>
Mark DrelingerMISAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lenamtlCommented:
I'm using this snippet

function refreshAt(hours, minutes, seconds) {
    var now = new Date();
    var then = new Date();

    if(now.getHours() > hours ||
       (now.getHours() == hours && now.getMinutes() > minutes) ||
        now.getHours() == hours && now.getMinutes() == minutes && now.getSeconds() >= seconds) {
        then.setDate(now.getDate() + 1);
    }
    then.setHours(hours);
    then.setMinutes(minutes);
    then.setSeconds(seconds);

    var timeout = (then.getTime() - now.getTime());
    setTimeout(function() { window.location.reload(true); }, timeout);
}

refreshAt(9,33,0); //Will refresh the page at 9:33

Open in new window

Zakaria AcharkiAnalyst DeveloperCommented:
With the current code if you're using 60000 milliseconds your code will remain refreshing from 08:00 until 23:59 but you need to use :

location.reload();

Open in new window


Instead of :

window.refresh();

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark DrelingerMISAuthor Commented:
That worked to refresh at a specific time, but not during work hours.  and since the refreshAt is set specifically, I don't see how it can be altered accordingly ?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Zakaria AcharkiAnalyst DeveloperCommented:
javascript to reset html page during work hours.

The description in your question does not help much, Please try to describe to us your final goal, what you want to achieve exactly so we could help more.
lenamtlCommented:
You need to refresh to which frequency?
Mark DrelingerMISAuthor Commented:
Yes, I should have been clearer. I want the page to refresh every x seconds, but only drying work hours, specifically 8am to 5pm.
Page to stay idle between non-work hours.
Mark DrelingerMISAuthor Commented:
refresh every 10 minutes.
Mark DrelingerMISAuthor Commented:
This worked. Thanks to all

//60000 milliseconds is 1 minute
window.setInterval("checkForRefresh()", 60000);

function checkForRefresh() {
   var now = new Date();
   if (now.getHours() >= 7 && now.getHours() <= 18) {
    location.reload();
   }
}
Mark DrelingerMISAuthor Commented:
Thanks all.  
Excellent code
//60000 milliseconds is 1 minute
window.setInterval("checkForRefresh()", 60000);

function checkForRefresh() {
   var now = new Date();
   if (now.getHours() >= 7 && now.getHours() <= 18) {
    location.reload();
   }
}
Zakaria AcharkiAnalyst DeveloperCommented:
Then you need just to add a condition to your current one like :

if (now.getHours() > 7 && now.getHours() < 17) {
    window.refresh();
 }

Open in new window

Zakaria AcharkiAnalyst DeveloperCommented:
Good job you find it.

specifically 8am to 5pm.

Just as a side note , your current condition :
if (now.getHours() >= 7 && now.getHours() <= 18) {

Open in new window


Will include 7am and 6pm , be careful. If you want to exclude them check my previous comment...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.