UL Element Object For HTML element properties, methods, and event handlers, see Chapter 15.. Syntax Accessing UL element object properties and methods: IE4+ [window.]document.all.elemID.
Trang 1The startproperty governs which number or letter begins the sequence of leading characters for nested LI items If the TYPEattribute specifies numbers, then the corresponding number is used; if it specifies letters, then the letter of the alpha-bet corresponding to the number becomes as the starting character You can change the numbering in the middle of a sequence via the LI.valueproperty
It is an extremely rare case that requires you to modify this property for an existing OL element But if your script is creating a new element for a segment of ordered list items that has some other content intervening from an earlier OL ele-ment, you can use the property to assign a starting value to the OL group
Example on the CD-ROM
Related Items:type, LI.valueproperties
type
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
An OL element can use any of five different numbering schemes Each scheme has a type code, whose value you can use for the typeproperty The following table shows the property values and examples:
The default value is 1 You are free to adjust the property after the table has ren-dered, and you can even stipulate a different type for specific LI elements nested inside (see the LI.typeproperty) If you want to have further nesting with a differ-ent numbering scheme, you can nest the OL elemdiffer-ents and specify the desired type for each nesting level, as shown in the following HTML example:
<OL TYPE=”A”>
<LI>One
<LI>Two
On the
CD-ROM
OL.type
Trang 2<OL TYPE=”a”>
<LI>Sub One
<LI>Sub Two
<LI>Sub Three
</OL>
<LI>Four
</OL>
Indenting the HTML is optional, but it may help you to keep the nesting straight
Example on the CD-ROM
Related Items:start, UL.type, LI.typeproperties
UL Element Object
For HTML element properties, methods, and event handlers, see Chapter 15
compact†
type
†See OL Element Object.
Syntax
Accessing UL element object properties and methods:
(IE4+) [window.]document.all.elemID.property | method([parameters])
(IE5+/NN6) [window.]document.getElementById(“elemID”).property |
method([parameters])
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
About this object
The UL (unordered list) element is a container of LI (list item) elements An
unordered list means that the list items have no sequence and are preceded by
sym-bols that don’t signify any particular order The few element-specific attributes are
being deprecated in favor of style sheet definitions For the sake of backward
com-patibility with existing content, however, it is likely that many future generations of
browsers will continue to support these deprecated attributes These attributes are
therefore available as properties of the element object
On the
CD-ROM
UL
Trang 3Most of the special appearance of a list (notably indentation) is handled auto-matically by the browser’s interpretation of how an ordered list should look You have control over the three possible characters that precede each item
Properties type
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
A UL element can use any of three different leading characters Each character type has a type code whose value you can employ for the typeproperty Property values are circle, disc, and square The difference between a circleand discis that the circleis unfilled, while the discis solid The default value is disc Example on the CD-ROM
Related Items:OL.type, UL.typeproperties
LI Element Object
For HTML element properties, methods, and event handlers, see Chapter 15
type value
Syntax
Accessing LI element object properties and methods:
(IE4+) [window.]document.all.elemID.property | method([parameters]) (IE5+/NN6) [window.]document.getElementById(“elemID”).property |
method([parameters])
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
On the
CD-ROM
LI
Trang 4About this object
An LI (list item) element contains the HTML that is displayed for each item
within an OL or UL list Note that you can put any HTML you want inside a list item,
including images Attributes and properties of this element enable you to override
the specifications declared in the OL or UL containers (except in IE/Mac)
Properties
type
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
Because either an OL or UL container can own an LI element, the typeproperty
accepts any of the values that you assign to the typeproperties of both the OL and
UL element objects See the OL.typeand UL.typeproperties earlier in this chapter
for lists of those values
Exercise caution, however, if you attempt to mix and match types For example, if
you try to set the LI.typeproperty of an LI element to circleinside an OL
ele-ment, the results vary from browser to browser NN6, for example, follows your
command; however, IE may display some other characters
Example on the CD-ROM
Related Items:OL.type, UL.typeproperties
value
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
The valueproperty governs which number or letter is used for the current list
item inside an ordered list Employ this attribute and property to override the
natu-ral progression Because these sequence characters can be letters, numbers, or
Roman numerals, the integer you specify for this property is converted to the
num-bering scheme in force by the LI or OL element’s typeproperty
On the
CD-ROM
LI.value
Trang 5Example on the CD-ROM
Related Item:OL.startproperty
DL, DT, and DD Element Objects
For HTML element properties, methods, and event handlers, see Chapter 15
compact†
†See OL Element Object.
Syntax
Accessing DL, DT, and DD element object properties and methods:
(IE4+) [window.] document.all.elemID.property | method([parameters]) (IE5+/NN6+) [window.] document.getElementById(“elemID”) property |
method([parameters])
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
About these objects
Three elements — DL, DT, and DD — provide context and (optionally) formatting for definitions in a document The DL element is the outer wrapper signifying a defi-nition list Each defidefi-nition term should be inside a DT element, while the defidefi-nition description should be in the nested DD element The HTML for a simple definition list has the following structure:
<DL>
<DT>First term
<DD>First term’s definition
<DT>Second term
<DD>Second term’s definition
</DL>
While there are no specific requirements for rendering definition lists by conven-tion, the term and description are usually on different lines with the description indented
All three of these elements are treated as element objects, sharing the same properties, methods, and event handlers of generic element objects The only one
On the
CD-ROM
DL
Trang 6of the three that has anything special is the DL element, which has a compact
prop-erty IE4+ for Windows does respond to this attribute and property by putting the
description and term on the same line if the term is shorter than the usual
indenta-tion space of the descripindenta-tion
DIR and MENU Element Objects
For HTML element properties, methods, and event handlers, see Chapter 15
compact†
†See OL Element Object.
Syntax
Accessing DIR and MENU element object properties and methods:
(IE4+) [window.]document.all.elemID.property | method([parameters])
(IE5+/NN6) [window.]document.getElementById(“elemID”) property |
method([parameters])
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5
About these objects
The DIR and MENU elements are treated in modern browsers as if they were UL
elements for unordered lists of items Both elements are deprecated in HTML 4.0;
yet, because they are acknowledged in that standard, they are also acknowledged
in the W3C DOM (and the IE DOM, too) Originally intended to assist in creating
sin-gle and double columns of text (long since supplanted by tables), usage of these
elements has fallen out of favor and is discouraged
DIR
Trang 8The Navigator
and Other
Environment
Objects
Client-side scripting primarily focuses on the document
inside a browser window and the content of the
docu-ment As discussed in Chapter 16, the window, too, is an
important part of how you apply JavaScript on the client But
stepping out even one more level is the browser application
itself Scripts sometimes need to know about the browser and
the computing environment in which it runs so that they can
tailor dynamic content for the current browser and operating
system
To that end, browsers provide objects that expose as much
about the client computer and the browser as is feasible within
accepted principles of preserving a user’s privacy In addition
to providing some of the same information that CGI programs
on the server receive as environment variables, these
browser-level objects also include information about how well equipped
the browser is with regard to plug-ins and Java Another object
defined for NN4+ and IE4+ reveals information about the user’s
video monitor, which may influence the way your scripts
calcu-late information displayed on the page
The objects in this chapter don’t show up on the document
object hierarchy diagrams, except as freestanding groups (see
Appendix A) The IE4+ object model, however, incorporates
these environmental objects as properties of the window
object Because the windowreference is optional, you can
omit it for IE and wind up with a cross-browser, compatible
script in many cases
Where the IE (for Windows anyway) and NN environments
diverge significantly is in the way scripts can find out whether
a particular plug-in or support for a particular MIME type is
available in the current browser As you learn in this chapter,
28
In This Chapter
Determining which browser the user has Branching scripts according to the user’s operating system
Detecting plug-in support
Trang 9the IE for Windows methodology can be a bit roundabout And yet the Macintosh version of IE5+ has adopted the approach initiated by NN3 Go figure
clientInformation Object (IE4+) and navigator Object (All)
appCodeName javaEnabled() appMinorVersion preference() appName taintEnabled() appVersion
browserLanguage cookieEnabled cpuClass language mimeTypes onLine oscpu platform plugins product productSub securityPolicy systemLanguage userAgent userLanguage userProfile vendor vendorSub
Syntax
Accessing clientInformationand navigatorobject properties and methods:
(All) navigator.property | method() (IE4+/NN6) [window.]navigator.property | method() (IE4+) [window.]clientInformation.property | method()
navigator
Trang 10About this object
In Chapter 16, I repeatedly mention that the windowobject is the top banana of
the document object hierarchy In other programming environments, you likely can
find a level higher than the window — perhaps referred to as the application level.
You may think that an object known as the navigatorobject is that
all-encompass-ing object That is not the case, however
Although Netscape originally invented the navigatorobject for the Navigator 2
browser, Microsoft Internet Explorer also supports this object in its object model
For those who exhibit partisan feelings toward Microsoft, IE4+ provides an alternate
object —clientInformation— that acts as an alias to the navigatorobject You
are free to use the IE-specific terminology if your development is intended only for
IE browsers All properties and methods of the navigatorand
clientInformationobjects are identical In the rest of this section, all references
to the navigatorobject also apply to the clientInformationobject
Be aware that the number of properties for this object has grown with virtually
every browser version Moreover, other than some basic items that have been
around since the early days, most of the more recent properties are
browser-spe-cific Observe the compatibility ratings for each of the following properties very
carefully
Most of the properties of the navigatorobject deal with the browser program
the user runs to view documents Properties include those for extracting the
ver-sion of the browser and the platform of the client running the browser Because so
many properties of the navigatorobject are related to one another, I begin this
discussion by grouping four of the most popular ones together
Properties
appCodeName
appName
appVersion
userAgent
NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
These four properties reveal just about everything that browser-sniffing code
needs to know about the user’s browser brand, version, and other tidbits Of these
four, only the last three are particularly valuable The first property in the list,
appCodeName, defines a class of client that encompasses essentially every standard
browser The value returned by browsers, Mozilla, is the code name of the first
browser engine on which NN and IE browsers at one time were based (the NCSA
Mosaic browser) This information does nothing to help your scripts distinguish
among browser flavors, so you can ignore the property But the other three
proper-ties are the ones with all the goodies
navigator.appCodeName