Scripts for JavaScript

This page provides quick links to common tasks that you may perform with JavaScript.

Browser functions

  • Display browser information — this example shows how to gather information about a user's browser.
  • Browser based redirect — this script redirects a browser to a specific desired page based on the browser's version number.
  • Detect platform — is it Windows, Macintosh or some other platform used to access the web page? Find out with this script.

Date and time functions

One of ways to make your pages dynamic and interactive is to utilize the date and time functions available in JavaScript. Follow the links below to see some examples of date and time functions.

  • Hour based greeting — this is a simple script that prints a greeting message based on the hour of the day.
  • Get current month name — this scripting function returns the current name of the month (e.g., January, February, or March etc.).
  • Get current day — this script shows how to get the current name of the day (e.g., Sunday, Monday, or Tuesday etc.) of the week.
  • Time-related functions — this script includes number of functions that shows how to get specific time-related values: year, month, day of the month, day of the week, hour of the day, minutes, and seconds.
  • Digital clock — shows a simple script that can display a digital clock.
  • Seconds since last refresh — this code shows how to use a counter variable to determine when a web page was last refreshed. The code uses the JavaScript setTimeout () method to update the counter variable every second.