Web Page Design Boot Camp

  Home |  Basics |  Intermediate |  Advanced |  Tools |  Site Map    Subtopics:

JavaScript Sampler

You don't have to be a programmer to use JavaScript routines. Below are some short JavaScript functions that you can copy and paste into your own web pages.

Web Page Footer

If you want to add the URL for the page being displayed by the browser to the bottom of the document, insert the following script to the bottom of the body section of the HTML. It should go immediately before the <body> tag.

<script language="JavaScript">
<!--
document.writeln('<p><hr><i>' + document.URL + '</i>')
// -->
</script>

The output looks like:

Displaying the Date & Time

Here is a script that will display the current system date and time when the web page was loaded.

<script language="JavaScript">
<!--
var currentDate = new Date()
document.writeln('Today is <b>' + currentDate + '</b>')
// -->
</script>

The output looks like:

Date Only Format

If you want to display just the current date in a mm/dd/yyyy format, you can insert this script in the body section.

<script language="JavaScript">
<!--
var currentDate = new Date()
var theMonth = currentDate.getMonth() + 1
var theDay = currentDate.getDate()
var theYear = currentDate.getYear()
if (theYear < 1900) {theYear += 1900}
document.write("Today is <b>" + theMonth + "/" + theDay + "/" + theYear + "</b>")
// -->
</script>