Overview: Sample Script
To get some sense of the forest before we start sorting out the trees, let's look at a simple JavaScript and examine its components:
<script language="JavaScript">
<!--
/* This script tells displays the browser name and version being used.
It is more complicated and less efficient than it should be,
for the sake of clarity.
Legend:
Red = keyword
Blue = variable
Purple = operator
Olive = function
Teal = control structure
Black = object
Navy = property
Fuchsia = method
Green = comment
Note that these colors will only be visible if your
browser supports Cascading Style Sheets
*/
/* set variables equal to browser
name and version and add another equal
to the integer portion of "version" */
var browser=navigator.appName;
var version=navigator.appVersion;
var ver1=version.substring(0,1);
/* Write the identity of the browser and version */
document.write("Your browser is " + browser + "<br>");
document.write("The version is " + version + "<br>");
// check for Netscape 4+
if ((browser == "Netscape") && (ver1 >= 4))
{
/* write a message to the Netscape crowd */
document.write("<b>You are using a great browser!</b>");
}
else {
checkIE()
}
function checkIE(){
// check for IE 4+
if ((browser == "Microsoft Internet Explorer") && (ver1 >= 4))
{
/* write this to the IE crowd */
document.write("<b>You are using a terrific browser!</b>");
}
else {
tellUser(); // otherwise, go to this function
}
}
/* the functions writes a different message to the uncool */
function tellUser() {
document.write("Your browser is old!");
}
-->
</script>
|
We'll take a quick look at these components in the next page.
|