Home
Date and Time
Here
|
Categories
Other Sections
Sweet Ads
Compatibility
|
|
FF1+ IE5+ Opr7+
Universal Countdown Script Author: Dynamic
Drive
Description: There are basically two types of JavaScript countdown scripts, depending on what you're trying to do. The first type counts down using the time of the visitor's computer, which obviously varies depending on the visitor, and is great for counting down to "relative" events such as Christmas, your friend's birthday etc (See "Dynamic Countdown script"). The second type counts down using a specific local time (ie: Time in New York), and is great for counting down to "absolute" events where the target date/time is tied to a certain time zone, such as the launch date of a web site, the date/time of the next Solar Eclipse etc. This is a Universal Countdown script that lets you count down to absolute events, by using your server's time to derive the local time in which the event is based on. The target date to count down to can be specific to the second if needed (ie: "April 23, 2009 2:37:30"). This script is extremely flexible- you can customize exactly how to display the output, or even specify a custom action to perform at the end of the countdown (ie: go to another page), by passing in your own custom format function. Requirement: The page running this script must either be PHP, SSI (server side includes), or ASP enabled, as the script needs to rely on one of these technologies to access your server's time. Demos: Example 1 (base unit: hours):: Example 2 (base unit: days):: Step 1: Insert the below script into the HEAD section of your page: Step 2: Inside your <BODY>, define a DIV or SPAN tag with a unique ID that will contain the local time, then invoke "cdLocalTime()" to populate it: <div id="cdcontainer"></div> Here's an explanation of the 4 parameters of: cdLocalTime("ID_of_DIV_container", "server_mode", LocaltimeoffsetMinutes, "target_date", "opt_debug_mode")
Ok, you're almost out of the woods. There's still a method of the function you need to be familiar with. Here's an explanation of the 2 parameters of: cdLocalTime.displaycountdown("base_unit", formatfunction_reference)
That's it, at least as far as general installation of the script is concerned. We've included a couple of helpful information below. Q1) How do I calculate the "LocaltimeoffsetMinutes" value for my desired local time?Answer: Start off by displaying the current server time on your page first, by setting "LocaltimeoffsetMinutes" to 0 and enable the last debug parameter (by entering the string "debugmode"):<script type="text/javascript"> With debugging mode turned on, the script will now display the current local time of your server live (since LocaltimeoffsetMinutes is set to 0). Now that you know your server time, look up the actual current local time you wish the script to be based on, then change 0 to be the offset in minutes between this local time and your current server time (ie: -120). Reload the page, and see if the local time displayed is now the correct local time, and once it is, you can turn off debugging (remove the last "debugmode" parameter). Q2) How do I customize the output or even behaviour of the countdown?Answer: The script lets you pass in your own format function as the second parameter of cdLocalTime.displaycountdown(). This enables you tremendous flexibility as far as how to customize the script output. Inside the code of Step 1 above, we've included two sample format functions. Lets take a look at the 2nd one, which displays the nice LCD countdown you see in demo #2: /////CUSTOM FORMAT OUTPUT FUNCTIONS
BELOW////////////////////////////// Obviously to be able to take full advantage of this script, you'll need to be familiar with some JavaScript. That unfortunately is beyond the scope of this script!
|