/    Sign up×
Community /Pin to ProfileBookmark

Problem Running Script based on Day and Time

I have a relatively simple question. I have a redirection script that works fine based on the time of day. I want to expand the script a bit to allow it to work based on day and time. The way it is now, the script works every day between the specified hours. I want to make it work only on a specified day and then between two specified hours. The second script below does not work and I suspect I am using the operators wrong.

//This first script works
var TLCGISwebsiteDown=””;
var now = new Date();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()

if (hours>=3) && (hours<6)) //execute based on day and time.

{
TLCGISwebsiteDown=”maintenance”;
if (hours==3)
{
TLCGISwebsiteDown=””;
}
}

if (TLCGISwebsiteDown==”maintenance”) {
window.location.href(“WebsiteDown.htm”);
}

//This second script does not work
var TLCGISwebsiteDown=””;
var now = new Date();
var thisday = now.getDay();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds()

if ((thisday==2) && (hours>=3) && (hours<6)) //execute based on day and time.

{
TLCGISwebsiteDown=”maintenance”;
if (hours==3)
{
TLCGISwebsiteDown=””;
}
}

if (TLCGISwebsiteDown==”maintenance”) {
window.location.href(“WebsiteDown.htm”);
}

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameApr 08.2009 — window.location.href is not a function, don't use ().

Try:

window.location.href = "WebsiteDown.htm";
×

Success!

Help @JacobC spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...