Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: Web
Expertise: Intermediate
Jun 4, 1999



Application Security Testing: An Integral Part of DevOps

Redirect Based on Time of Day Using JavaScript

Redirecting based on the time of day is fairly easy to do. One thing to remember, however, is that because client-side JavaScript runs in the user's browser, the time your code will be working with is the time set on the user's machine, not your Web server. This factor is especially important if your site gets a lot of international visitors. That said, here's one way to code a time-based redirect:
function ampmRedirect(dayURL, nightURL)
	var currentTime;
	var currentHour;

	// get the current date and time
	currentTime = new Date();

	// returns the hour in military time
	currentHour = currentTime.getHours();
	// check if the hour is between 6pm and 6am
	if ((currentHour < 6) || (currentHour > 17)) {
		window.location = nightURL;
	} else {
		window.location = dayURL;
// -->
Click here to go to the next page:<BR>
<INPUT TYPE="button" VALUE="Next"
Boris Feldman
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date