| And this is the HTML page: <html>
<head>
<script language="JavaScript">
<!--
function whatBrowser() {
document.Form1.Name.value=navigator.appName;
document.Form1.Version.value=navigator.appVersion;
document.Form1.Code.value=navigator.appCodeName;
document.Form1.Agent.value=navigator.userAgent;
}// -->
</script>
</head>
<BODY onLoad="whatBrowser()">
<CENTER>
<TABLE BORDER>
<FORM NAME="Form1">
<TR>
<TD> Browser Name: </TD>
<TD> <INPUT TYPE="text"
NAME="Name"
Size="35"></TD>
</TR>
<TR>
<TD> Browser Version: </TD>
<TD> <INPUT TYPE="text"
NAME="Version"
Size="35"></TD>
</TR>
<TR>
<TD> Browser Code Name: </TD>
<TD> <INPUT TYPE="text"
NAME="Code"
Size="35"></TD>
</TR>
<TR>
<TD> User-Agent: </TD>
<TD> <INPUT TYPE="text"
NAME="Agent"
Size="35"></TD>
</TR>
</FORM>
</TABLE>
</CENTER>
</body>
</html>
Ok, ok, I'm going to explain...
As you can see, although this
HTML source is quite long, there are a few of thing
to understand. I wrote them in different colors.
Blue colors
These things are objects: Document and Navigator
Orange colors
These things are properties
Ok, the Navigator object has
some properties, for example its name (appName) and
its version (appVersion). You can read these
properties so: Navigator.property...
In the table above, there are 4
fields. Each field has a name. For example, the
second field's name is 'Version'. Notice that
Javascript is case sensitive, so 'Version' is quite
different from 'version'; if you forget that, you
will get an error by Javascript.
Do you remember the objects hierarchy? Well, to use the field 'Version' you
have to call it so: Document.Form_name.Version. There
is just a document object, so you have not to call it
in a specific way. But a single document could
contain several 'form', and so you have to specify
the name of the form which you want to use. A form
could contain several fields, buttons and so on, so
you have to specify the name of the field which you
want to use (for example 'Version'). Value is a
property. A field has several properties: value is
one of them. If you want to put something inside of a
field, you have to put it inside of 'value'. In other
words you have to assign a value to the field.
Hence this statement:
Document.Form1.Version.Value=Navigator.appVersion
In this way, you are saying to
the browser: 'hey, browser, please assign your
version to the value of field Version of the form
Form1 of the Document...'.
Finally OnLoad: this is an event-handler. The event is
Load. So, when the HTML page is loading, a Load event
occurs. In this case, the OnLoad event-handler calls
the whatBrowser function.
As you can see, the real
Javascript code is just a few of lines!
|