Javascript Programmer's Reference 9781861004598, 1861004591

JavaScript is the scripting language of the Web. Its widespread use in web applications, and support in all modern brows

257 89 17MB

English Pages 2625 Year 2001

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

Javascript Programmer's Reference
 9781861004598, 1861004591

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

PROGRAMMER TO PROGRAMMER

TM

e-book includes this complete reference and 2000+ extra entries

Build your Web Development career with Wrox

JavaScript Programmer’s Reference

Cliff Wootton

JavaScript Programmer's Reference

Cliff Wootton

Wrox Press Ltd. 

JavaScript Programmer's Reference © 2001 Wrox Press

All rights reserved. No part of this book may be reproduced, stored in a retrieval system or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews. The author and publisher have made every effort in the preparation of this book to ensure the accuracy of the information. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, Wrox Press nor its dealers or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.

Published by Wrox Press Ltd, Arden House, 1102 Warwick Road, Acocks Green, Birmingham, B27 6BH, UK Printed in the United States ISBN 1-861004-59-1

Trademark Acknowledgements Wrox has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Wrox cannot guarantee the accuracy of this information.

Credits Author Cliff Wootton

Technical Editors Timothy Briggs Howard Davies Phillip Jackson Amanda Kay Simon Mackie Chris Mills Peter Morgan

Technical Reviewers Alex Abacus Jonny Axelsson Chong Chang Andrew Van Heusen Martin Honnen Ron Hornbaker Kenneth Lo Jim Macintosh Jon Stephens Peter Torr Chris Ullman Paul Vudmaska Paul Wilton

Project Manager Chandima Nethisinghe

Figures Shabnam Hussain

Production Coordinator Tom Bartlett

Cover Shelley Frazier

Additional Layout Simon Hardware Pippa Wonson

Proofreaders Ian Allen Christopher Smith Agnes Wiggers

Category Manager Dave Galloway

e-Book Production Tom Bartlett Production Manager Simon Hardware

Index Andrew Criddle

About the Author Cliff Wootton lives in the south of England and works on multimedia systems and content management software for large data driven web sites. Currently he is developing interactive TV systems for BBC News Online in London (http://www.bbc.co.uk/news) and previously worked for other commercial broadcasters on their web sites. Before that he spent several years developing geophysical software and drawing maps with computers for oil companies. Cliff is married with three daughters and a growing collection of bass guitars.

Acknowledgements It's hard to believe I've actually reached the stage of writing the introductory pages to this book. It's been a long process and I don't think I would have reached this point without the help of Tim Briggs at Wrox, who very gently urged me onwards and gave me encouragement when I needed it. Tim's contribution to this project was vital to its success because he developed the process which converted my DOCBOOK output into something the Wrox editors could turn into a book. Tim also prepared the CD-ROM content from the same XML files; truly amazing! Thanks also to all the other folks at Wrox who have helped, organised, checked and collated my material to present it in the form you now see it. Grateful thanks to my reviewers, who in a very short time provided me with some useful guidance and support; in particular Jon Stephens and Martin Honnen, who also provided some amazingly clever example code fragments for use as examples. There are many other people who contributed without realising it. In particular Nick Cohen (formerly of the BBC and now at Turner Broadcasting) who provided some helpful insights into TV set-top-box workings. Also Matt Karas and Emyr Tomos (both ex-BBC, now at Talkcast) who threw down the gauntlet of several interesting challenges for me to implement on the BBC News Online web site. I also wouldn't be sitting here if it weren't for Bruce Morris at Carlton Online. It was through the happy chance of an article I wrote for Bruce's Web Developer's Journal (WDJ) web site that led to Wrox contacting me and the BBC inviting me to do some JavaScript work. What an amazing thing the web is. Most importantly I dedicate this book to my family. To my wife, Julie and my daughters Hannah, Lydia and Ruth who kept me going with cups of coffee, hugs and the occasional giggle when they saw the photograph of me for the front cover.

Introduction The JavaScript language is constantly developing, and continues to increase in popularity. Its evolution into a general purpose scripting language from what started life purely for scripting web browsers, is a great success story. You can now find JavaScript interpreters in many different environments and there are sure to be other new and interesting uses for the language in the future, especially now that embeddable interpreters are available. In this book, we have attempted to snapshot the browsers that exist currently, which need to be supported by web sites, and collate that information together in a form that has broad scope and is deep enough to be useful on a day-to-day basis. As the language is growing all the time, this is likely to be an ongoing task.

Who is This Book For? The book is aimed at people who already have some knowledge of JavaScript and need a companion volume to their daily work. It is primarily aimed at the experienced practitioner, and so does not attempt to be a tutorial for the beginner. For a tutorial book, we suggest Paul Wilton's Beginning JavaScript (Wrox Press, ISBN 1-861004-06-0). Typical uses of the book include times when you: ❑

Need to check out the specific details of a particular language construct or object property



Know what you want to do, but want to know how JavaScript helps you achieve that



Want information on cross-browser compatibility issues for your script



Have encountered a problem in your script and need help to debug it

One important motivation I had for writing this book was to reduce the amount of material I have to carry around when I'm working on projects in my clients' offices. My library now contains several shelves devoted purely to JavaScript, and in researching this book, I ended up with many megabytes of material. There have been many fine books written about JavaScript but I simply cannot carry them around on the train, even with a large rucksack! So, I set out to try and distil enough useful information into one book and organize it so that the information is easy to find. I've also put in material on issues that I've encountered in discussions with other programmers.

JavaScript Programmer's Reference

The Structure of the Book To make it easy to navigate through the topics, titles describe the topic content and the topic type and are organized alphabetically. Where a topic might be referred to using several headings, a brief entry in the cross-reference at the end of the book shows the main topic for that subject. I used a great deal of software automation to manage the book content and the whole thing was built in a database and exported as an XML file set using the DocBook DTD. There are now in excess of 3500 individual topics in this work. That is more than twice as many as we have room for in the printed book, so we’ve had to put a useful subset of the reference into the printed book, and the complete set of material onto the CD-ROM, which is available both in PDF and HTML formats. Some additional reference information that is not strictly part of the JavaScript language, but that you may find useful, is also included, such as country codes and MIME types. Where we discuss an object all the important properties, methods, events, and any supporting material are broken out into their own topics, and these detailed entries are included on the CD. Where objects inherit properties and methods, they are listed in the object coverage, but to avoid duplication the information about the inherited properties is described as a member of the super-class. This slightly detracts from the lexical referencing but it saves space. In some cases these inherited properties/methods are deemed important enough to merit a cross-referencing entry of their own. This allows us to indicate availability of features at a very fine level of detail. Within each topic we can also discuss bugs, gotchas, and areas of difficulty in a focused way. Language syntax is illustrated by way of example code fragments that show how to access an object, method, or property. More extensive examples are given where necessary. Because of the scoping rules, properties are available without the need for the window object to be specified as a prefix. Thus navigator as a topic is available under the window.navigator topic as well. Once you have found an entry topic, you can then use the cross-referencing listings to locate other related material. The book content was developed inside a database system, which provided tools to relate topics. The benefit is a rich source of cross-referencing links between topics. The cross-reference in the printed book is complete; that is, it also includes entries found only on the CD. The italicized crossreferences in the printed book can also be found in the printed book. We will now look at some of the 'features' of JavaScript programming, as an introduction to what topics in the book will address.

Differences between Browsers For some time, the most popular browsers have been Netscape Navigator 4.7 and Microsoft Internet Explorer 5.0 (MSIE). Other, newer browsers make a point of being standards compliant and so if your script conforms to the standards for core JavaScript as laid down by ECMA and the W3C DOM specifications, it should function correctly. However, the dominant browsers have for a long time been competing with one another to add new features. Architecturally, this means their browsers have each gone in a completely different direction. The penalty has been that support for various language features has been implemented in each browser in ways that makes it difficult to use in a portable way. Indeed, to make use of some features requires twice the work, since the same code has to be written in two different ways and called after detecting which browser is being used.

2

Introduction

Because of the proliferation of browser versions and platforms, features are generally referred to as being available in the revision in which they were first introduced. As the Netscape browser is available on so many different platforms, to test for compliance across all platforms would require a test suite of a dozen machines and 30 or more different installations of browser applications. Indeed, when building such a test suite just prior to starting on this book, I found more than a dozen distinctly different browser versions just for the Macintosh platform and many more than that for Windows. Similarly, MSIE comes in a bewildering variety of versions and platform variants. In addition, the JScript interpreter is a replaceable component that can be upgraded without changing the containing browser.

Browsers and Standards There is still much that is ambiguous or not yet defined in the standards and the browser manufacturers continue to add new features in competition with one another. Even though they are standards compliant at a functional level, there are still significant differences if you 'look under the hood'. We have included coverage of the following standards: ❑

ECMAScript core language up to edition 3 of the standard



DOM coverage to level 1



Some DOM coverage of level 2 where implemented in Netscape 6



Discussion of the features being added at DOM level 3

JavaScript implementations we cover include: ❑

Netscape 3.0, 4.0, 4.05, 6.0 (the final release came out as we went to press)



MSIE version 3.0, 4.0, 5.0, 5.5



Opera 3, 4, 5



Netscape Enterprise Server

By implication that means we cover JavaScript versions up to 1.5 and JScript up to 5.5. The coverage of Netscape 6.0 is based on it supporting the W3C DOM standards and several bugs in the currently released version prevented the verification of some functionality although that may be platform dependent. There are also some new and unexpected features. We concentrate our discussions on the peculiarities of Netscape and MSIE because the other browsers that support JavaScript attempt to provide a fault-free standards-based implementation. Since this is a sub-set of the functionality of Netscape and MSIE, other platforms should be adequately covered.

Features and Versions There are now a wide variety of sources of information about JavaScript and they don't all agree. In particular there is some uncertainty over which release of JavaScript introduces certain features. The source material was assimilated by examining the standards documents and by inspecting objects with fragments of JavaScript. Then, the availability of features was checked against several alternative reference works. Occasionally, when a consistency error showed up, it was necessary to go back to the browser and test for the availability of a property or method.

3

JavaScript Programmer's Reference

Where there is some room for doubt, we have documented the release at which the feature became useful. This is because in earlier releases it may have had a serious flaw or been significantly revised later to make it work properly. Any implementation prior to that may be unreliable. So where we may appear to disagree with other commentators our coverage is based on whether it is practical to use a particular feature at a certain release. Some browser features are available at an earlier release on some platforms than others are. We take the Windows 32-bit release as our baseline although significant testing was also done on the Macintosh versions, which disappointingly lagged somewhat in performance and feature availability. Both platforms exhibited instabilities and crash-prone behavior but in quite different areas of the language. As there are so many variants of the browsers, the availability matrix for objects and their member properties/methods is huge and requires a large amount of work to test on all the available combinations. So far, no single reference source has proven to be error free and whilst the information here has been examined and cross-checked it is still likely that there are errors. If, in your work, you disagree with the information provided here, please send feedback (see the end of the Introduction for how to do this).

Core JavaScript At first glance, the JavaScript environment appears to be built around a small core of objects and it is easy to fall into the trap of assuming the language is small and compact. That is certainly true if you are only considering core JavaScript functionality. The core language is defined by ECMA and both Netscape and MSIE both claim to be ECMA compliant. They may well be, but you cannot write much useful JavaScript for deployment in a web page by confining yourself only to the functionality of the ECMA standard. It is at that point that the two browsers begin to diverge.

DOM Support Likewise, both browsers (MSIE 5 upwards and Netscape 6) claim to be DOM compliant. Browser support for the DOM is slowly converging but if you need to do any esoteric code development that involves DOM traversal and class names, they are still somewhat different. MSIE implements a DOM model that is structurally right, but the class names of the objects that comprise that model are certainly not correct and do not conform to the DOM standard. Netscape 6 implements a DOM compliant model that does use the correct class names. Another slight difference is that MSIE implements distinctly different classes for some objects whereas Netscape Navigator instantiates the same class for several purposes. These differences don't cause much grief to you when you are constructing simple scripts and web page enhancements but can be quite a problem if you need to manipulate the DOM structure and operate on objects by means of their class names. This difference did not become apparent until I used inspection scripts to examine internal document structures. There are also areas where DOM specifies objects in a way that the browsers can implement ambiguously. For example, DOM describes documents as being a generic document class with an HTML document as a sub-class. Browsers simply provide a single document class with no access to the two separate class types.

4

Introduction

Object Classes You might also assume that there is a small and finite set of different object types. However if you inspect the constructor properties and examine the function names, you will find the opposite, there are a large number of object types. For example, the applets property that returns a list of applets in a document will give you an AppletArray object and not a Collection object in Netscape. Trying to work out class names on MSIE is a bit more problematic and it tends to provide generic Collection objects instead. By building fragments of JavaScript to inspect objects, you can determine these class names and learn a lot about how the browser maintains the internal model of the page. The topics are constructed around a browser-centric model. The objects are defined based on their instantiation by an HTML tag in a web browser window. MSIE creates a distinct object class for each tag. Netscape does a similar trick, but not so convincingly in earlier versions. At version 6, the objects are DOM compliant and named differently to those in MSIE and earlier Netscape browsers. Netcsape 6 is so different as to be a new browser with little similarity to the earlier versions of Netscape. There is an emerging standards-based model that frames the object hierarchy much more logically and, while it is still evolving, it may become a more robust way of describing the catalog of available classes. For now, though, the web and browser dominate use of JavaScript, so this seems like the more appropriate model.

Document Objects Another area of debate is the document object. Typically, the previous documentation describes access to it as if there is only one document object. This is true within the context of a single script within a page. However, it is not necessarily true of a window in a web browser. A window may contain many frames or layers. Each one will have its own private document object. If you are writing scripts that operate across multiple frames or windows, you may refer to several document objects, so the syntax examples are designed to accommodate the different ways in which objects can be accessed.

The Future JavaScript is becoming available in an ever-wider variety of applications. It is used in: ❑

PDF forms for validation



For modifying the behavior of the GUI in developer tools



Embedded interpreters in cell phones and television set-top boxes

There was not space enough or time to cover these extensively. They are also changing continually and will not be stable enough to document for a while yet.

What Do I Need to Use This Book? All that is needed to use this book is a text editor and a JavaScript-enabled browser, such as Microsoft Internet Explorer or Netscape Navigator. To use the CD you will need a browser to read the HTML files and a copy of Adobe Acrobat Reader/Adobe Acrobat eBook Reader to read the PDF files, which are freely available from www.adobe.com. To make navigation easier, the PDF files contain interactive bookmarks, thumbnails, and hyperlinks in the entries. All of the code examples given in the book are available on the CD, and are also available to download from our web site, www.wrox.com.

5

JavaScript Programmer's Reference

Conventions Used in This Book The convention used for syntax naming is that a variable created within the local scope would be prefixed with my while a global variable would be prefixed with the. Parameters passed into function and method calls are prefixed with a, an, or some. The syntax description for an object shows how a reference to an object of that class can be retrieved via a property or method on another object. The syntax for properties and methods show them as members of an object that is referred to with a variable. This manifests itself as an object reference like this: myDocument myDocument myDocument myDocument

= = = =

document myElement.parentNode myFrame.document myLayer.document

Then a property reference looks like this, myDocument.cookie

and not: document.cookie

Of course you can omit the indirection through a referencing variable and any of these would be equally valid: document.cookie myElement.parentNode.cookie myFrame.document.cookie myLayer.document.cookie

But by using the indirection, the syntax descriptions for the member properties and methods are simplified. In the tables, we have used the abbreviations N for Netscape, NES for Netscape Enterprise Server, and IE for Internet Explorer. As for styles in the text:

6



Filenames, and code in the text appear like so: dummy.xml



Test on user interfaces, and URLs, are shown as: File/Save As…

Introduction

Customer Support Wrox has three ways to support books. You can: ❑

Post and check for errata at www.wrox.com



Enroll at the peer-to-peer forums at p2p.wrox.com



Email technical support a query or feedback on our books in general

Errata You can check for errata for the book at our web site; www.wrox.com, simply navigate to the page for this book. There will be a link to the list of errata.

P2P Lists You can enroll in our peer to peer discussion forums at p2p.wrox.com. The JavaScript list is available in the 'Web Design' section.

Email Support If you wish to point out an errata to put up on the website or directly query a problem in the book with an expert who knows the book in detail, then e-mail [email protected]. A typical email should include the following things: ❑

The name of the book, the last four digits of the ISBN and the entry name for the problem in the Subject field



Your name, contact info and the problem in the body of the message

You may want to tell us your opinion of this book, or you may have ideas about how it can be improved, in which case, e-mail [email protected]. We will do our utmost to act upon your comments.

7

A object (Object/HTML) An object that represents an element when instantiated in MSIE. Availability:

JScript –1.0 Internet Explorer –3.02

Inherits from:

Element object, Node object

JavaScript syntax:

IE

myA = myDocument.all.anElementID

IE

myA = myDocument.all.tags("A")[anIndex]

IE

myA = myDocument.all[aName]

IE

myA = myDocument.anchors.item(aName)[anIndex]

-

myA = myDocument.anchors[aName]

-

myA = myDocument.anchors[anIndex]

-

myA = myDocument.getElementById(anElementID)

-

myA = myDocument.getElementsByName(aName)[anIndex]

-

myA = myDocument.getElementsByTagName("A")[anIndex]

IE

myA = myDocument.links.item(aName)[anIndex]

-

myA = myDocument.links[aName]

-

myA = myDocument.links[anIndex]

HTML syntax: Argument list:

... anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

Object properties: accessKey, dataFld, dataSrc, hash, host, hostname, href, Methods, mimeType, nameProp, pathname, port, protocol, protocolLong, rel, search, tabIndex, target Event handlers:

onBlur, onClick, onDblClick, onFocus, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

See also:

Element object, Input.accessKey, Map object, Anchor object

A – A object (Object/HTML)

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

accessKey dataFld dataSrc hash host hostname href Methods mimeType nameProp pathname port protocol protocolLong rel search tabIndex target

1.5 + -

3.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 1.0 + 3.0 + 1.0 +

6.0 + -

4.0 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 3.02 + 4.0 + 3.02 +

-

1+ 1+ 1+ 1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onBlur onClick onDblClick onFocus onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart

-

3.0 + 1.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 1.0 + 3.0 + 3.0 +

-

4.0 + 3.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.0 + 4.0 + 4.0 +

-

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

9

JavaScript Programmer's Reference

ABBR object (Object/HTML) An object representing the HTML content (an abbreviation) delimited by the HTML tags. Availability:

HTML version – 4.0 JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object, Node object

JavaScript syntax:

IE

myABBR = myDocument.all.anElementID

IE

myABBR = myDocument.all.tags("ABBR")[anIndex]

IE

myABBR = myDocument.all[aName]

-

myABBR = myDocument.getElementById(anElementID)

-

myABBR = myDocument.getElementsByName(aName)[anIndex] myABBR = myDocument.getElementsByTagName("ABBR")[anIndex]

HTML syntax: Argument list:

... anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

10

Event handlers:

The ID value of an Element object onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp

See also:

style.speak, Element object

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick onDblClick onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp

1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 +

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning

A – about: URL (Request method)

about: URL (Request method) This is a special kind of URL that fetches content from a storage area inside the Netscape browser instead from using HTTP to get it from a web server. Availability:

JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0

This is a special request method provided by the Netscape browser to gain access to local clientside resources. The resources are loaded from inside the application itself. In the Macintosh version of Navigator, this means they are stored in the resource fork of the browser application. If you need to deploy a custom version of Navigator within an intranet environment, with some care you can modify these resources with a resource-editing tool, such as ResEdit. Always work on a copy of the application and test the changes thoroughly. On other platforms, the resources are likely to be stored in files located in folders adjacent to the application. You will need to study your own copy of Netscape to see what you can change. These special URLs are mostly not present in early versions of MSIE, although there will be some internal resources, which may provide customization opportunities. MSIE also supports an about:blank URL that provides a blank page. There may be others hidden away inside the application. You may also be able to obtain administration tools from Netscape and Microsoft to carry out legitimate customizations on the browsers before deploying them throughout your organization. The following special URLs seem to work when typed into the location box: URL

Description

about:logo

Netscape logo

about:mozilla

A fire & brimstone quote from the book of Mozilla (Yes it's really there – at least on some versions)

about:authors

Shows a cryptic message about the page having been removed, although the authors.html file is still present inside the application

about:cache

Displays a disk cache report

about:document

Displays the document info console

about:fonts

Displays the font info console

about:global

A global history report

about:image-cache

A report on the internal image cache

about:license

A hyperlink to the Netscape license document

about:mailintro

Displays the Netscape mail info page

11

JavaScript Programmer's Reference

URL

Description

about:memory-cache

A report on the memory cache

about:pics

Generates a security exception

about:plugins

A page of information about the plugins

about:security?advisor=XXX

Brings up a security console where XXX indicates the window to operate on.

about:security?banner-insecure

Serves an unlocked padlock image

about:security?banner-secure

Serves a locked padlock image

about:security?issuer-logo=XXX

Returns a graphic where XXX identifies which one

about:security?subject-logo=XXX

Returns a graphic where XXX identifies which one

about:coslogo2

Cosmo logo

about:fclogo

Full Circle software logo

about:hslogo

Beatnik logo

about:hype

An audio clip

about:insologo

Inso logo

about:javalogo

Java compatible logo

about:litronic

Litronic logo

about:mclogo

Marimba Castanet logo

about:mmlogo

Macromedia logo

about:ncclogo

Netcast logo

about:odilogo

Object Design logo

about:qtlogo

Apple QuickTime logo

about:rsalogo

RSA secure logo

about:symlogo

Symantec logo

about:tdlogo

TrueDoc logo

about:visilogo

VisiGenic logo

about:blank

Presents a blank page on Netscape Navigator 3 and MSIE version 5; used to create a blank page when a new window is opened

Some of these URLs can be used in frames, but others can't. A few can be used as HREF values. JavaScript complains that the about: request method is illegal. This means you cannot change the location.href within a page to any of the "about:" URLs. However, you might be able to write some innerHTML content into a or to place a link to these assets. Many of the built-in assets are used as image sources in the about page. It's possible you might want to display the Netscape logo. If you are aware that you are using software provided by the other third parties, you might (if they give you permission) place their logo on the screen when you are using features of their software. You should ask first, although Netscape probably won't mind their logo being served like this.

12

A – abstract (Reserved word)

The interesting thing about this is that you are effectively serving assets out of a static cache in the client file system. The URL that points at the license document may be useful as it is possible you might want to display the Netscape license if you are redistributing the browser. The about:plugins URL yields a page containing some useful JavaScript that displays the plugins page. You may find some useful techniques in here for managing plugin facilities although they may be Netscape compatible only. Mostly, these special URLs will be useful for debugging. Getting details of the disk cache, for example, may be useful. Pulling up the JavaScript debugger page if you detect an error in your script might also be a cool trick. The MSIE and Netscape browsers can both use the about:blank URL value as a default page when the browser is started up.

Warnings: ❑

The UniversalBrowserRead privilege is required for access to internal browser values and state information such as the cache contents. See also:

javascript: URL, nethelp: URL, UniversalBrowserAccess, UniversalBrowserRead, URL

abstract (Reserved word) Reserved for future language enhancements.

Refer to: Reserved word

Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3

AbstractView object (Object/DOM) An object that belongs to the DOM level 2 views module. Availability:

DOM level – 2 JavaScript – 1.5 Netscape – 6.0

JavaScript syntax:

N

myAbstractView = myMouseEvent.view

N

myAbstractView = myUIEvent.view

13

JavaScript Programmer's Reference

This is part of a new suite of functionality introduced at DOM level 2, which provides a way of looking at documents from alternative points of view. At present only the Abstract and Document views are standardized and, because the capabilities are quite new, implementations may be incomplete at this stage. See also:

MouseEvent object, MouseEvent.initMouseEvent(), UIEvent object

Accessor method (Definition) A method for accessing publicly available object properties. Availability:

ECMAScript edition – 2

A method used to store or retrieve property values contained in objects. In ECMAScript-compliant implementations, this is accomplished with internal functions named Get() and Put(). If you add new properties to an object of your own, you may want to implement functions that operate by using the 'this' variable to access properties. These functions are then associated with the object or its prototype, so that they can be shared. They are then referred to as methods rather than functions. See also:

function( ... ) ..., Get(), Method, Put()

Cross-references: ECMA 262 edition 2 – section – 8.6.2 ECMA 262 edition 3 – section – 8.6.2

ACRONYM object (Object/HTML) An object representing the HTML content delimited by the HTML tags. Availability:

JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object, Node object

JavaScript syntax:

IE

myACRONYM = myDocument.all.anElementID

IE

myACRONYM = myDocument.all.tags("ACRONYM")[anIndex]

IE

myACRONYM = myDocument.all[aName]

-

myACRONYM = myDocument.getElementById(anElementID)

-

myACRONYM = myDocument.getElementsByName(aName)[anIndex] myACRONYM = myDocument.getElementsByTagName("ACRONYM")[anIndex]

-

14

A – Activation object (Object/internal)

HTML syntax: Argument list:

... anElementID

The ID value of the element required

anIndex

A reference to an element in a collection

aName Event handlers:

An associative array reference onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

See also:

style.speak, Element object

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick onDblClick onDragStart onFilterChange onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart

1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + -

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + -

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + -

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

Activation object (Object/internal) The activation object is created when the flow of control first enters an execution context. Availability:

ECMAScript edition – 2

The activation object is created when the flow of control first enters an execution context for declared function code, anonymous code or implementation-supplied code.

15

JavaScript Programmer's Reference

As the activation object is created, it is associated with the execution context. On initialization, it has a property called arguments that cannot be deleted and that refers to an arguments object. This activation object is then used as the variable object for instantiating all the argument variables. The activation object is discarded when the function returns its result to the caller. The activation object is an internal mechanism and so cannot be passed to the outside world, although members of the activation object may well be accessible to a running script. See also:

Execution context, function(…) ...

Cross-references: ECMA 262 edition 2 – section – 10.1.6 ECMA 262 edition 3 – section – 10.1.6

Active Server Pages (Product) A Microsoft web server product. This is a server-side programming framework that supports JavaScript. More accurately, it supports JScript, which is Microsoft's flavor of JavaScript. For more information, see ASP 3.0 Programmer's Reference, ISBN 1-861003-23-4 from Wrox Press. See also:

BODY.recordNumber, Event.bookmarks[], Event.boundElements[], Input.recordNumber, SCRIPT.recordNumber, Server-side JavaScript, TextStream object

ActiveX (Product) This is a Microsoft technology for embedding and sharing code. In MSIE (on Windows), interactions between scripts and applets takes place by means of ActiveX. Microsoft prefers to treat applets as a special kind of ActiveX object. Netscape shows a similar preference towards treating applets as Java components. If you are developing web-based applications for a captive audience who you know will be running MSIE on Windows, then this technology may be appropriate for your project. However, ActiveX is not supported on Netscape and, in fact, is unlikely to be well supported on any other browsers aside from MSIE. Coupling this with the fact that it is not supported outside the Windows platform, you will almost certainly find Java to be a more portable solution. The Java solution is also secured better than ActiveX, which can expose the internals of your system in ways you would rather avoid.

16

A – ActiveXObject object (Object/JScript)

For a high degree of Windows integration and a very Microsoft-oriented solution, ActiveX is ideal. For portability across platforms and browsers, it's likely you'll do much better to select Java. See also:

Applet object, Dictionary object, Glue code, LiveConnect

Web-references: http://msdn.microsoft.com/scripting/

ActiveXObject object (Object/JScript) A Windows and MSIE specific object that allows various document components to be embedded. Availability: JavaScript syntax:

JScript – 3.0 Internet Explorer – 4.0 myActiveX = ActiveXObject IE IE

myActiveX = new ActiveXObject (anApplication)

Argument list:

anApplication

References an external application

Collections:

Depends on the object created by the constructor

This is an object for embedding other applications into web pages on the Windows platform. The example shows the creation of an object that is managed by the Word application. This is also used to create Dictionary objects by using the Scripting application to create a new Dictionary object.

Warnings: ❑

This is totally non-portable and non-standard, but if your scripts are likely to be deployed in a Windows-only environment, it may be useful.



Using this construct in client-side scripting is subject to security restrictions. If a script in a web browser could just instantiate Word, then that implies that it has rights of access to the local file system. The normal IE security settings disallow that level of access.

Example code: // An example that opens a Word document and writes // text into it. var myActiveX = new ActiveXObject("Word.Document"); myActiveX.Application.Visible=true; myString="Some text to be written to the document"; // now write the text to the word document myActiveX.application.selection.typeText(myString);

See also:

Dictionary object, OBJECT object

17

JavaScript Programmer's Reference

ActiveXObject() (Constructor) Used for manufacturing new ActiveX objects. Availability: JavaScript syntax:

Argument list:

JScript – 3.0 Internet Explorer – 4.0 new ActiveXObject(anObjectType) IE IE

new ActiveXObject(anObjectType, aLocation)

anObjectType

What sort of application and object class type to be created

aLocation

A server name where the source object is located

You can use this constructor for creating new objects. You need to specify the kind of object to be created in the string argument value.For example, to create a Microsoft Word document, pass the string "Word.Document" to the constructor. You can also specify a second optional argument to locate the application on a remote server. Here are some example applications you can invoke: ❑

Word.Document – Create an empty Word document



Excel.Sheet – Create an empty Excel spreadsheet



Microsoft.XMLDOM – Create a new XML document

Other alternatives depend on the applications you have installed on your client system. See also:

GetObject()

Add (+) (Operator/additive) Add two numeric operands together. See concatenation for Strings. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

anOperand1 + anOperand2

anOperand1

An expression that evaluates to a number

anOperand2

Another expression that evaluates to a numeric value

Argument list:

18

A – Add (+) (Operator/additive)

The addition operator adds two numeric values together or concatenates one string onto another. When used with numeric operands, the plus sign adds the values together. The addition is commutative, meaning that the order of the operands does not affect the outcome of the calculation. However, the calculation is not always associative (so (a+b)+c is not always the same as a+(b+c)) and so the precedence established with the grouping operator might affect the outcome. The associativity is left to right. Refer to the operator precedence topic for details of execution order. If either operand is NaN, the result will be NaN. The sum of infinity and minus infinity will be NaN; they do not cancel one another out. The sum of two infinity values of the same sign will be the infinity of that sign. The sum of infinity and a finite value is equal to the infinite operand. Internally the sum of two negative zero values is -0. However, the sum of two positive zero value or a positive and negative zero value added together will be +0. At the scripting level however, you cannot determine whether a zero is positive or negative, but its sense may affect subsequent computations. The sum of zero and a non-zero value will be the non-zero value. The sum of two non-zero finite values of the same magnitude but opposite signs will be zero. Provided neither an infinity, a zero nor NaN is involved, adding two finite values results in the sum of the two values given that the result will be rounded to its nearest representable value. Where the result exceeds the largest presentable value, infinity will be substituted. A negative infinity may result from an underflow. The addition/concatenation operator looks at the arguments and if either is a String already or preferentially converts to one, then a concatenation occurs. If neither operator prefers to be a String, then a Number conversion happens and the values are added. See also:

Add then assign (+=), Additive expression, Additive operator, Associativity, Negation operator (-), Operator Precedence, String concatenate (+), Subtract (-), Type conversion, Unary expression, Unary operator

Cross-references: ECMA 262 edition 2 – section – 11.6.1 ECMA 262 edition 2 – section – 11.13 ECMA 262 edition 3 – section – 11.6.1 Wrox Instant JavaScript, ISBN 1-861001-27-4 – page – 37

19

JavaScript Programmer's Reference

Add then assign (+=) (Operator/assignment) Add two numeric operands and assign the result to the first. See concatenation for Strings. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

anOperand1 += anOperand2

anOperand1

An expression that evaluates to a number

anOperand2

Another numeric value

Argument list:

Add the right operand to the left operand and assign the result to the left operand. This is functionally equivalent to the expression: anOperand1 = anOperand1 + anOperand2; Although this is classified as an assignment operator, it is really a compound of an assignment and an additive operator. It also works with string values and will concatenate the second onto the first. The associativity is right to left. Refer to the operator precedence topic for details of execution order. The new value of anOperand1 is returned as a result of the expression.

Warnings: ❑

The operand to the left of the operator must be an LValue. That is, it should be able to take an assignment and store the value.

Example code: // Initialize with numeric valuesmyVar1 = 100;myVar2 = 1000; // After this myVar1 contains 1100, myVar2 is unchanged myVar1 += myVar2;

See also:

20

Add (+), Additive operator, Assign value (=), Assignment expression, Assignment operator, Associativity, Concatenate then assign (+=), Increment value (++), LValue, Operator Precedence, Subtract then assign (-=)

A – Adding JavaScript to HTML (Advice)

Cross-references: ECMA 262 edition 2 – section – 11.13 ECMA 262 edition 3 – section – 11.13

Adding JavaScript to HTML (Advice) The most popular use of JavaScript is in web pages. Adding it is quite simple. To add JavaScript to a web page, you can use the following techniques: ❑

The

See also:

Document.anchors[], Document.links[], Element object, Element.all[], Input.accessKey, LINK object, Location object, String.anchor(), Subclasses, Superclasses, URL, Url object, Window.scrollTo()

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

accessKey

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

charset

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

-

coords

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

-

dataFld

-

3.0 +

-

4.0 +

-

-

-

-

dataSrc

-

3.0 +

-

4.0 +

-

-

-

-

hash

1.2 +

3.0 +

4.0 +

4.0 +

-

-

-

Warning

host

1.2 +

3.0 +

4.0 +

4.0 +

-

-

-

Warning

hostname

1.2 +

3.0 +

4.0 +

4.0 +

-

-

-

Warning

href

1.2 +

3.0 +

4.0 +

4.0 +

-

1+

-

Warning

hreflang

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

-

Methods

-

3.0 +

-

4.0 +

-

-

-

-

mimeType

-

3.0 +

-

4.0 +

-

-

-

Warning, ReadOnly

name

1.2 +

3.0 +

4.0 +

4.0 +

-

1+

-

Warning

nameProp

-

3.0 +

-

4.0 +

-

-

-

ReadOnly

pathname

1.2 +

3.0 +

4.0 +

4.0 +

-

-

-

Warning

port

1.2 +

3.0 +

4.0 +

4.0 +

-

-

-

Warning

protocol

1.2 +

3.0 +

4.0 +

4.0 +

-

-

-

Warning

protocolLong

-

3.0 +

-

4.0 +

-

-

-

ReadOnly

recordNumber

-

3.0 +

-

4.0 +

-

-

-

ReadOnly

rel

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

rev

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

Table continued on following page

28

A – Anchor() (Constructor)

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

search

1.2 +

3.0 +

4.0 +

4.0 +

shape

1.5 +

5.0 +

6.0 +

5.0 +

-

-

-

Warning

-

1+

-

-

tabIndex

1.5 +

3.0 +

6.0 +

target

1.2 +

3.0 +

4.0 +

4.0 +

-

1+

-

-

4.0 +

-

1+

-

Warning

text

1.2 +

-

4.0 +

-

-

-

-

Warning, ReadOnly

type

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

urn

-

x

1.2 +

3.0 +

-

4.0 +

-

-

-

-

-

4.0 +

-

-

-

-

Warning, ReadOnly

y

1.2 +

-

4.0 +

-

-

-

-

Warning, ReadOnly

Method

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

blur()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

focus()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick

1.2+

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOut

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

Anchor() (Constructor) You can construct new Anchor objects in Netscape. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

Anchor object

JavaScript syntax:

N

new Anchor

N

new Anchor()

N

new myAnchor.constructor

Although you can construct new anchors in Netscape, inserting them into a document is somewhat problematic since the correct way to do that would be to rewrite a fragment of HTML. You may find that replacing an anchor object in the document.anchors array links your new object to the HTML tag at the appropriate location in the document.

29

JavaScript Programmer's Reference

Warnings: ❑

This is only available on Netscape and is therefore not recommended for use in deployable applications. MSIE generates a run-time error if you attempt to make a new Anchor object. See also:

Anchor object, Anchor.host

Anchor.accessKey (Property) A key that needs to be pressed before the anchor object will respond to data entry. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myInputObject.accessKey

This is an extension that allows the anchor elements to be deadlocked unless a certain key is held down. On some browsers and operating systems, you may need to hold down one of the modifier keys for this to work. The modifier key required depends on the environment you are using.

Warnings: ❑

This is not supported in some versions of the MSIE browser on Macintosh.

Anchor.blur() (Method) Remove input focus from the Anchor object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

myInputObject.blur()

This will trigger the onblur event handler function attached to the onblur property of the object.

30

A – Anchor.charset (Property)

Anchor.charset (Property) This property indicates the character encoding of the document at the location specified by the URL. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.charset

This would contain the character set being used by the document. For example the value "iso-8859-1" is likely to be returned, but the local variant of the browser and OS may affect the value you get. This property might contain a value such as: csISO5427Cyrillic Details of other aliases can be located at the IANA registry. In that registry are listed the names and aliases of a wide variety of character sets. Even though there are nearly 800 names and aliases, it seems on inspection that there are items missing. See also:

LINK.charset, Url.charset

Web-references: ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets

Anchor.coords (Property) This defines an area map within an image that is inside the HTML tags. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.coords

When a shaped area is defined within an image map, the rectangle around the shape is defined with the coords property. The value is defined with the COORDS HTML tag attribute. See also:

Anchor.shape, Area.coords, Url.coords

31

JavaScript Programmer's Reference

Anchor.dataFld (Property) This binds the anchor object to a remote data source in MSIE. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myInputObject.dataFld

This is part of the MSIE data-binding mechanism that associates a column name in the data source with the value property of an Anchor object. You must also set the dataSrc property for the object. Normally, both the dataFld and dataSrc values would be defined with the DATAFLD and DATASRC HTML tag attributes in the document source. Note that the value is case-sensitive and must refer to a column that exists within the data source. Setting both the dataFld and dataSrc properties to an empty string will disconnect the element from the database.

Anchor.dataSrc (Property) The name of a remote ODBC data source is stored in this property. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myInputObject.dataSrc

This is part of the MSIE data-binding support. It contains the name of an ODBC data source (which might be any kind of SQL database that supports such an adapter). The data source and element are bound together with each column of the data source providing a source value to different element objects through their dataFld property. Normally, both the dataFld and dataSrc values would be defined with the DATAFLD and DATASRC HTML tag attributes in the document source. Setting both the dataFld and dataSrc properties to an empty string will disconnect the element from the database.

32

A – Anchor.focus() (Method)

Anchor.focus() (Method) Brings input focus back to the anchor object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

myInputObject.focus()

The receiving Anchor object will receive a Focus event trigger and execute its function referred to by the onfocus event handler property. The element that previously had focus (if any element did) will receive a Blur event trigger.

Anchor.hash (Property) On MSIE the Url.hash property is also available as the Anchor.hash property. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.hash

-

myAnchor.hash = newValue

HTML syntax:

This yields the hash suffix of the HREF value in an tag. You can assign a new value to this property, which will become a new anchor location within the document.

Warnings: ❑

This attribute may not work correctly when URLs are accessed from one frame to another in some versions of MSIE. You should check your target platforms for compliance.



If you assign a value to this property in MSIE, you should omit the leading hash.



Since the hash property of an Anchor object is not portable in all older browser versions, you should use the pathname property of the corresponding Url object to be able to work across MSIE and Netscape.



As features become deprecated, it may become necessary to support both techniques in browserspecific code according to your needs regarding the support of legacy browsers.

33

JavaScript Programmer's Reference

See also:

Anchor object, Anchor.host, Anchor.hostname, Anchor.href, Anchor.pathname, Anchor.port, Anchor.protocol, Anchor.search, Anchor.target, URL, Url.hash, Url.host, Url.hostname, Url.href, Url.pathname, Url.port, Url.protocol, Url.search, Url.target

Anchor.host (Property) On MSIE the link.host property is also available as the anchor.host property. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.host

-

myAnchor.host = newHostPort

HTML syntax:

This yields the host and port value of the HREF value in an tag. You can redefine the host to request the URL by assigning a new value to this property.

Warnings: ❑

Since the host property of an Anchor object is not portable in all older browser versions, you should use the pathname property of the corresponding Url object to be able to work across MSIE and Netscape.



As features become deprecated, it may become necessary to support both techniques in browserspecific code according to your needs regarding the support of legacy browsers. See also:

34

Anchor object, Anchor(), Anchor.hash, Anchor.href, Anchor.pathname, Anchor.port, Anchor.protocol, Anchor.search, Anchor.target, URL, Url.host

A – Anchor.hostname (Property)

Anchor.hostname (Property) On MSIE the link.hostname property is also available as the anchor.hostname property. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.hostname

-

myAnchor.hostname = newHostname

HTML syntax:

This yields the host value of the HREF value in an tag. You can redefine the hostname to request the URL by assigning a new value to this property.

Warnings: ❑

Be careful not to assign a port number with the host name, otherwise your new URL may acquire two port numbers, which makes it invalid.



Since the hostname property of an Anchor object is not portable in all older browser versions, you should use the pathname property of the corresponding Url object to be able to work across MSIE and Netscape.



As features become deprecated, it may become necessary to support both techniques in browserspecific code according to your needs regarding the support of legacy browsers. See also:

Anchor object, Anchor.hash, Anchor.href, Anchor.pathname, Anchor.port, Anchor.protocol, Anchor.search, Anchor.target, URL, Url.hostname

Anchor.href (Property) On MSIE the link.href property is also available as the anchor.href property. Availability:

DOM level – 1 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.href

-

myAnchor.href = newHref

HTML syntax:

35

JavaScript Programmer's Reference

This yields the entire value of the HREF attribute in an tag. You can redefine the entire HREF content by assigning a new value to this property.

Warnings: ❑

Since the href property of an Anchor object is not portable in all older browser versions, you should use the pathname property of the corresponding Url object to be able to work across MSIE and Netscape.



As features become deprecated, it may become necessary to support both techniques in browserspecific code according to your needs regarding the support of legacy browsers. See also:

Anchor object, Anchor.hash, Anchor.host, Anchor.hostname, Anchor.pathname, Anchor.port, Anchor.protocol, Anchor.search, Anchor.target, Location.href, URL, Url.href

Anchor.hreflang (Property) The language code of the document at the location specified by the URL. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.hreflang

This property should contain values that use the international language two-letter abbreviation codes. These are not the same as the country codes, which are also two letter values. Refer to the Language codes topic for a list of the available language codes. See also:

Language codes, LINK.hreflang

Anchor.Methods (Property) A property that can indicate some keywords regarding the action that the server provides when the link is clicked on. These reflect the request methods.

36

Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myAnchor.Methods

A – Anchor.mimeType (Property)

The possible values of this property are those of the valid methods for the HTTP protocol. It could be one of the following: ❑

GET



HEAD



POST



PUT



DELETE



OPTIONS



TRACE

It is likely that only the GET and POST methods make any logical sense in this context. On rare occasions, the PUT method may be referred to, although it is unusual to find a web server that accepts documents with this request method. Likewise DELETE is normally only supported within very strict constraints. The method name can be specified in upper or lower case. See also:

Url.Methods

Anchor.mimeType (Property) Contains a long form human readable version of the MIME type of the document at the location specified by the anchor's URL. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myAnchor.mimeType

The MSIE browser maps the file extension of the file belonging to the anchor to an extended description of the file format, which it makes available through the mimeType property. Here is a list of some mimeType values it pays special attention to. File type:

MSIE expanded Mime type:

.css

Microsoft CSS1 Style Sheet (W3C would have been more appropriate)

.gif

GIF Image

.htc

Microsoft HTML Component file for behaviors

.htm

Microsoft HTML Document 4.0

.html

Microsoft HTML Document 4.0

.jpg

JPEG Image

37

JavaScript Programmer's Reference

File type:

MSIE expanded Mime type:

.js

Microsoft JScript File

.txt

Text Document

.vbs

Microsoft VBScript File

.xxx

All unrecognized file types are returned as xxx File with no further expansion

Microsoft asserts that .htm and .html files are "Microsoft HTML" and .css files are "Microsoft CSS1" style sheets. It also asserts that .js files are "Microsoft JScript" files. Microsoft doesn't really own those file extensions across all platforms, nor indeed does it even own them on the Windows platform.

Warnings: ❑

Do not confuse this value with other mimeType properties. For example the Navigator object has a mimeTypes[] collection property with references to mimeType objects. The mimeType property of an MSIE Anchor object is a simple string primitive value and not a mimeType object. See also:

MIME types, Url.mimeType

Property attributes: ReadOnly.

Anchor.name (Property) This corresponds to the NAME attribute of the HTML tag. Availability:

DOM level – 1 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.name

-

myAnchor.name = aName

HTML syntax:

Argument list:

aName

A new name for the anchor.

The value of this property is defined by the NAME tag attribute in the HTML that describes the document. Without the NAME attribute, the anchor object does not get added to the anchors[] array.

38

A – Anchor.nameProp (Property) This name property contains a case-sensitive value. It is case-sensitive because it can be used as a value in one of the document hierarchies to locate an object. The example should present the word "EXAMPLE" on all compliant browsers.

Warnings: ❑

This value is read/write in MSIE, but read-only in Netscape. Logically there is not much purpose in changing the name of an anchor anyway.



Beware that assigning a new name will affect the length of the document.anchors[].



Changing the name in MSIE actually adds a new item to the document.anchors[] array that can be reached associatively with the new name. There will now be two entries for the same anchor and you can continue to access it using the old name as well.



If you are writing portable code and expect it to work in both MSIE and Netscape Navigator, this is the only property available in both browsers. Having located an anchor, being able to access only its name without any browser dependencies is rather limiting.

Example code:



Click here




See also:

Anchor object, AnchorArray.length, Document.anchors[], NAME="...", String.anchor(), Url.name

Anchor.nameProp (Property) The filename portion of the URL value. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myAnchor.nameProp

This property extracts the filename portion of the HREF value for this tag. See also:

Url.nameProp

Property attributes: ReadOnly.

39

JavaScript Programmer's Reference

Anchor.pathname (Property) In MSIE the Url.pathname property is also available as the Anchor.pathname property. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.pathname

-

myAnchor.pathname = newPath

HTML syntax:

This yields the pathname portion of the HREF attribute in an tag. MSIE and Netscape support the use of this property as an LValue. If you write to it, the pathname portion of the HREF value is modified. Be careful not to include a hash or search/query value.

Warnings: ❑

Since the pathname property of an Anchor object is not portable in all older browser versions, you should use the pathname property of the corresponding Url object to be able to work across MSIE and Netscape.



As features become deprecated, it may become necessary to support both techniques in browserspecific code according to your needs regarding the support of legacy browsers. See also:

Anchor object, Anchor.hash, Anchor.host, Anchor.hostname, Anchor.href, Anchor.port, Anchor.protocol, Anchor.search, Anchor.target, URL, Url.pathname

Anchor.port (Property) In MSIE the Url.port property is also available as the Anchor.port property. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.port

-

myAnchor.port = newPort

HTML syntax:

40

A – Anchor.protocol (Property) This yields the port number value of the HREF attribute in an tag. You can assign a value to this property as if it were an LValue.

Warnings: ❑

Since the port property of an Anchor object is not portable, you should use the port property of the corresponding Url object to be able to work across MSIE and Netscape.



Do not include the delimiting colon when you assign a value to this property.



Make sure you assign a numeric value. Non-numeric values will be rejected to avoid the possibility of a completely invalid port number being used. See also:

Anchor object, Anchor.hash, Anchor.host, Anchor.hostname, Anchor.href, Anchor.pathname, Anchor.protocol, Anchor.search, Anchor.target, URL, Url.port

Anchor.protocol (Property) In MSIE the Url.protocol property is also available as the Anchor.protocol property. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.protocol

-

myAnchor.protocol = newProtocol

HTML syntax:

This yields the protocol value of the HREF attribute in an tag. Using this property as an LValue, you can redefine the protocol for the link if it has an HREF. You might want to do this if you want to change the way you access a particular document. The URL topic enumerates a large number of available protocols that can be used in SRC and HREF HTML tag attributes.

Warnings: ❑

Since the protocol property of an Anchor object is not portable, you should use the protocol property of the corresponding Url object to be able to work across MSIE and Netscape.

See also:

Anchor object, Anchor.hash, Anchor.host, Anchor.hostname, Anchor.href, Anchor.pathname, Anchor.port, Anchor.search, Anchor.target, IMG.protocol, URL, Url.protocol

41

JavaScript Programmer's Reference

Anchor.protocolLong (Property) A long form description of the protocol used by the URL. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myAnchor.protocolLong

Only the MSIE browser supports this property. Its use would be limited even if it were available across multiple platforms. See also:

Url.protocolLong

Property attributes: ReadOnly.

Anchor.recordNumber (Property) The record within the data set that defined the element content when the content came from a data source. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myBody.recordNumber

This is a property that is part of the MSIE data-binding support. It contains an integer value that is the record number within the data set that created this object. This is useful when you are building pages with Active Server Pages (ASP) and ActiveX Data Objects (ADO).

Property attributes: ReadOnly.

42

A – Anchor.rel (Property)

Anchor.rel (Property) A definition of the relationship between the current document and the document at the location specified by the URL. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.rel

This is sometimes called a forward link. Although the HREF HTML tag attribute is normally the only means used to identify a target document, the browser is permitted to use the REL HTML tag attribute to decide whether to use the HREF value or how it should be used. The following HTML version 4.0 standard link types are permitted in this property: ❑

alternate



appendix



bookmark



chapter



contents



copyright



glossary



help



index



next



prev



section



start



stylesheet



subsection

MSIE adds these as well: ❑

same



next



parent



previous

When used or tested within a script, any comparisons should be case-insensitive. See also:

Anchor.rev, LINK.rel

43

JavaScript Programmer's Reference

Anchor.rev (Property) A complementary description of the link to the current document as viewed from the document at the location specified by the URL. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.rev

This is sometimes called a reverse link. It defines the relationship between a document and another that calls it. The linkage is defined from the destination document's viewpoint. This property supports the same HTML version 4.0 standard link types as the rel property. Refer to that topic for details. When used or tested within a script, any comparisons should be case-insensitive. Because rel and rev properties are complementary, the values in them are likely to be related. For example, if one contains the value "next" then the other is likely to contain "previous". Refer to the Anchor.rel topic for a list of the available types you can use in this property. See also:

Anchor.rel, LINK.rev

Anchor.search (Property) The query portion of an HREF URL if there is one. Availability:

JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.search

-

myAnchor.search = newSearch

HTML syntax:

Warnings: ❑

44

Since the search property of an Anchor object is not portable, you should use the search property of the corresponding link object to be able to work across MSIE and Netscape.

A – Anchor.shape (Property)

See also:

Anchor object, Anchor.hash, Anchor.host, Anchor.hostname, Anchor.href, Anchor.pathname, Anchor.port, Anchor.protocol, Anchor.target, request., URL, Url.search

Anchor.shape (Property) A map whose extent is defined by the coords property and which can be one of several different shapes. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.shape

This property has a meaningful value when the Anchor object is instantiated via and tag. It defines the shape of the hotspot within the extent rectangle defined by the coords property. It might contain one of the following values: ❑

default



rect



circle



poly See also:

Anchor.coords, Area.shape, Url.shape

Anchor.tabIndex (Property) A control of where the Anchor object appears in the tabbing order of the page. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myInputObject.tabIndex

45

JavaScript Programmer's Reference

This value indicates where in the tabbing sequence this object and any of its children will be placed. The tabbing order is used when filling in forms or moving focus. Pressing the [tab] key moves from one form element to the next according to the cascaded tabbing order defined by building a tree-like structure with the tab index values.

Anchor.target (Property) In MSIE the Url.target property is also available as the Anchor.target property. Availability:

DOM level – 1 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.target

-

myAnchor.target = newTarget

HTML syntax:

This yields the value of the TARGET attribute in an , , or tag. You can assign a new value to this property so that the URL will be directed to a different window or frame. Here are some example target values: ❑

_parent



_self



_top



_blank



Window name



Frame name

Warnings: ❑

Since the target property of an Anchor object is not portable, you should use the target property of the corresponding link object to be able to work across MSIE and Netscape. See also:

46

, Anchor object, Anchor.hash, Anchor.host, Anchor.hostname, Anchor.href, Anchor.pathname, Anchor.port, Anchor.protocol, Anchor.search, BASE.target, Form.target, Location.target, Map.target, URL, Url.target

A – Anchor.text (Property)

Anchor.text (Property) The text between the and HTML tags in Netscape. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

N

myAnchor.text

N

myAnchor.text = aString

HTML syntax:

someText

Argument list:

aString

Some new text content for the anchor

This is equivalent to the innerText value that MSIE supports. It only works on Netscape and is somewhat less reliable than the innerText property in MSIE. Assigning to this property in MSIE simply creates a text property, but does not affect the text of the anchor. The value yielded by this property (when it does work) is the text between the and tags.

Warnings: ❑

You will need to detect the browser type before attempting to use this property.



Does not work on Netscape Navigator version 4.7 on the Macintosh. Instead it displays some fragment of body text that comes from outside the anchor tags.



Even if it does work, you may only extract a portion of the text from the anchor. See also:

Anchor object, Element.innerText, Url.text

Property attributes: ReadOnly.

Anchor.type (Property) A MIME type value in its abbreviated machine recognizable form. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myAnchor.type

47

JavaScript Programmer's Reference

The MIME type of the document associated with the Anchor object is accessible through the value of this property. Refer to the MIME type topic for details of the available MIME types you will likely see in this property. See also:

LINK.type, MIME types

Anchor.urn (Property) An alternative format of the contents of the URL. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

See also:

URN

myAnchor.urn

Anchor.x (Property) The X location of the anchor within the document. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

N

myAnchor.x

N

myAnchor.x = aValue

aValue

A new X coordinate value

Argument list:

The Anchor.x property yields the pixel distance of the anchor from the left edge of the document. The horizontal position of the object in the display is measured in pixels. You can use the x and y coordinates of the object as targets of the scrollTo() method for the window it lives in.

Warnings: ❑

This is not supported by MSIE. Instead you can use the offsetLeft property that is inherited from the Element object super-class. There may be some occasions when this is not an exact equivalent value though. See also:

48

Anchor object, Element.offsetLeft, Location.x

A – Anchor.y (Property)

Property attributes: ReadOnly.

Anchor.y (Property) The Y location of the anchor within the document. Availability: Property/method value type: JavaScript syntax: Argument list:

JavaScript – 1.2 Netscape – 4.0 Number primitive N

myAnchor.y

N

myAnchor.y = aValue

aValue

A new Y coordinate value

The Anchor.y property yields the pixel distance of the anchor from the top edge of the document. The vertical position of the object in the display is measured in pixels. You can use the x and y coordinates of the object as targets of the scrollTo() method for the window it lives in.

Warnings: ❑

This is not supported by MSIE. Instead you can use the offsetTop property that is inherited from the Element object super-class. There may be some occasions when this is not an exact equivalent value though. See also:

Anchor object, Element.offsetTop, Location.y

Property attributes: ReadOnly.

AnchorArray object (Object/DOM) An array of Anchor objects retrieved from the document.anchors property. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 3.0 Internet Explorer – 4.0 Netscape – 2.0

JavaScript syntax:

-

Object properties:

length

myAnchorArray = myDocument.anchors

49

JavaScript Programmer's Reference

The AnchorArray object is a sub-class of the Array object but has no additional properties. It responds to the length property request as you would expect. Any Anchor objects in this array can be accessed by index value because the Array class supports that. In Netscape, the individual Anchor objects are accessible associatively by their NAME attribute. However, MSIE does not make this associative mechanism available. In MSIE, the AnchorArray object is a kind of Collection object and so it can be searched with the item() and tags() methods.

Warnings: ❑

Netscape adds a constructor property to this object class from which you can request the name to determine the object class. Actually Netscape provides constructors for virtually everything, but MSIE only supports them when it's necessary and useful.



Be aware that renaming an anchor in MSIE will add a new item to the AnchorArray collection without destroying the old one. However, the length property remains the same. It does mean that you could have problems enumerating the collection. But then, why would you ever want to rename an anchor after it has been instantiated and named within the HTML tag?

Example code:

anIndex

An item within the collection

aString

A comment string

aName

The name of an element

anElementID

The ID attribute of an element

Object properties:

text

Object methods:

click(), getAttribute(), removeAttribute(), setAttribute()

Collections:

all[], children[]

It is somewhat unlikely you would ever want to modify the contents of a comment tag. However, access to the text contained within it may be a way of passing hidden data values to your scripts without them being visible in the displayed page. Of course they would still be visible in the document source, but you might be able to avoid the creation of a and hidden object.

316

C – COMMENT.text (Property)

Warnings: ❑

The DOM level 1 specification describes this as a Comment object, but MSIE implements it as a COMMENT object instead. You may need to be aware of this in case other platforms implement the DOM specified class exactly as it is intended. See also:

CharacterData object, Document.createComment(), Element object, Hiding scripts from old browsers

Property

JavaScript

JScript

N

IE

Opera

DOM

Notes

text

-

3.0 +

-

4.0 +

-

-

-

Method

JavaScript

JScript

N

IE

Opera

DOM

Notes

click()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

Warning

getAttribute()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

Warning

removeAttribute()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

Warning

setAttribute()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

Warning

Inheritance chain: CharacterData object, Node object

COMMENT.text (Property) The text within a comment block. Availability:

JScript – 3.0 Internet Explorer version – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myCOMMENT.text

This is the internal text within the comment block. The DOM standard treats comment blocks as character data to standardize the access to their content, but you should not expect to be able to access the internal text of a comment for any functional purpose.

Compatibility (Definition) Creating web content is an exercise in portable programming that would severely test the most experienced programmer. There are so many issues to do with portability and compatibility that unless you are doing something very simple, its is an amazing achievement to get your web page to display even remotely similarly on several browsers or platforms.

317

JavaScript Programmer's Reference

Leaving aside the creative issues to do with color matching, gamma correction, and display resolution, there are problems with fonts, style sheets and table layout. Layers and dynamic HTML behave differently even within the same browser family as the browsers are revised. Even scrolling a page means you have to increment the scroll value in opposite directions in Netscape and MSIE, and Netscape won't scroll at all without the scroll bars being visible. To cope with this, it helps to break the compatibility issues down into sub-sets and to understand the underlying reason for incompatibility. You do need to know about and be able to identify issues based on platforms, browsers, or versions of client software. See also:

, block is placed with some global code to be executed if called for.

323

JavaScript Programmer's Reference

Warnings: This only works in Netscape 4 or later, which limits its usefulness somewhat. MSIE supports an alternative, but completely incompatible technique that only works inside the -->

See also:

Adding JavaScript to HTML

Conditional expression (Definition) Conditionally execute one code branch or another. Availability:

ECMAScript edition – 2

Conditional expressions test a logical expression and perform one of two possible alternative code blocks. The grammar for a conditional expression in ECMA-compliant JavaScript implementation is slightly different from that you may have seen before in Java and C language. Java and C set restrictions on the kind of expression you can put into the second code block, whereas JavaScript does not. This is a subtle distinction and is intended to simplify the use of this expression and avoid the use of a comma operator. See also:

Conditionally execute (?:), Expression

Cross-references: ECMA 262 edition 2 – section – 11.12 ECMA 262 edition 3 – section – 11.12 Wrox Instant JavaScript – page – 18

Conditional operator (Definition) Conditionally execute one code branch or another. Availability:

324

ECMAScript edition – 2

C – Conditionally execute (?:) (Operator/conditional)

Refer to: Conditionally execute (?:)

Cross-references: ECMA 262 edition 2 – section – 11.12 ECMA 262 edition 3 – section – 11.12

Conditionally execute (?:) (Operator/conditional) Conditionally execute one code branch or another. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Depends on arguments

JavaScript syntax:

-

Argument list:

aCondition ? someCode : moreCode

aCondition

A relational or logical expression that yields true or false

moreCode

Code that is executed if aCondition is false

someCode

Code that is executed if aCondition is true

The two associated code blocks are executed according to the value yielded by a Boolean test on the first operand. If it is true, then the first code block is executed, otherwise the second is used. The associativity is right to left. Refer to the Operator Precedence topic for details of execution order. This is sometimes called a Ternary operator, because it takes three operands.

Example code:





325

JavaScript Programmer's Reference

See also:

Associativity, Conditional expression, Flow control, if( ... ) ..., if( ... ) ... else ..., Operator Precedence, Selection statement, Ternary operator

Cross-references: ECMA 262 edition 2 – section – 11.12 ECMA 262 edition 3 – section – 11.12

config.jsc (Special file) A JavaScript configuration file for Netscape.

Refer to: Preferences

Cross-references: Wrox Instant JavaScript – page – 59

confirm() (Method) A dialog box to get confirmation from the user. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0

Property/method value type:

Boolean primitive

JavaScript syntax:

-

myResult = confirm(aString)

-

myResult = myWindow.confirm(aString) Some text to explain what is to be confirmed

Argument list:

aString

See also:

Window.alert(), Window.confirm()

326

C – Conformance (Definition)

Conformance (Definition) An interpreter may or may not conform to the ECMAScript specification. Availability:

ECMAScript edition – 2

Conforming implementations of ECMA 262 edition 2 must properly support Unicode version 2.0 and ISO/IEC 10646-1 with UCS-2 as the encoding form. There are various sub-clauses to that encoding requirement and implementers should build their systems around the specifications laid down therein. Edition 3 requires slightly different character coding support. Conforming implementations may provide additional capabilities. In particular, functionality flagged under the 'Future Reserved Word' category is encouraged by ECMA. A strictly conforming implementation is one that only provides the features outlined in the standard. Since ECMAScript only defines core functionality and absolutely none of the host environment, a strictly conforming implementation of ECMAScript would be of limited use. A conforming implementation provides the behavior outlined in the standard with some allowable additional behavior to support the hosting environment. See also:

Compliance, ECMA, ECMAScript, ECMAScript – edition 2, ECMAScript – edition 3

Cross-references: ECMA 262 edition 2 – section – 2 ECMA 262 edition 3 – section – 2

Connection object (Object/NES) An object that represents a connection from the server to the back-end database. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

JavaScript syntax:

NES

Argument list: Object properties: Object methods:

myConnection = myDbPool.connection(aName, aTimeout)

aName

A connection name

aTimeout

Timeout in seconds

prototype beginTransaction(), commitTransaction(), connected(), cursor(), execute(), majorErrorCode(), majorErrorMessage(), minorErrorCode(), minorErrorMessage(), release(), rollbackTransaction(), SQLTable(), storedProc(), toString()

This object is used to maintain the connection state details between the Netscape Enterprise Server and the backend database it is retrieving data from. A connection object is created by calling the connection() method of the DbPool object.

327

JavaScript Programmer's Reference

Example code:

// An example of how to create a connection object // Based on the one in Wrox Professional JavaScript myDbPool = new DbPool("ODBC", "myDatabase", "", "", ""); myConnection = myDbPool.connection("ExampleConnection", 30); myConnection.SQLTable("SELECT * FROM MY_TABLE");

See also:

DbPool.connection(), Netscape Enterprise Server, unwatch(), watch()

Property

JavaScript

JScript

NES

Notes

prototype

1.2 +

-

3.0 +

-

Method

JavaScript

JScript

NES

Notes

beginTransaction()

1.2 +

-

3.0 +

-

commitTransaction()

1.2 +

-

3.0 +

-

connected()

1.2 +

-

3.0 +

-

cursor()

1.2 +

-

3.0 +

-

execute()

1.2 +

-

3.0 +

-

majorErrorCode()

1.2 +

-

3.0 +

-

majorErrorMessage()

1.2 +

-

3.0 +

-

minorErrorCode()

1.2 +

-

3.0 +

-

minorErrorMessage()

1.2 +

-

3.0 +

-

release()

1.2 +

-

3.0 +

-

rollbackTransaction()

1.2 +

-

3.0 +

-

SQLTable()

1.2 +

-

3.0 +

-

storedProc()

1.2 +

-

3.0 +

Warning

toString()

1.2 +

-

3.0 +

-

Connection.beginTransaction() (Method) Commence a new transaction with the database. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

JavaScript syntax:

NES

myConnection.beginTransaction()

Call this method to signify the start of a new transaction with the database. This is a reference point to which you can rollback the changes if necessary. Note that you cannot rollback after the commit has occurred.

328

C – Connection.commitTransaction() (Method)

Connection.commitTransaction() (Method) Commit the changes made to the database. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

JavaScript syntax:

NES

myConnection.commitTransaction()

Relational databases support the facility of a two phase commit. That is, any changes made to the database require that a commit is requested before the session is disconnected. If the session is disconnected without a commit, then the changes are unwound and discarded leaving the database in the state it was in after the previous commit. Sometimes people place a commit after every transaction. This is somewhat wasteful and can lead to low performance. Placing a commit every 25 or so transactions is better. You do need to be sure that you have made the changes you need to and that any referential integrity is maintained and any constraints on the data are satisfied, otherwise the commit may fail.

Connection.connected() (Method) A method that returns a flag indicating the state of the connection. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

Boolean primitive

JavaScript syntax:

NES

myConnection.connected()

If the session is currently connected to the database, this method will return a true value. If the session is no longer connected it yields false.

Connection.cursor() (Method) Create a cursor object on the connection with the SQL database. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

Cursor object

JavaScript syntax:

NES

Argument list:

myConnection.cursor(aQuery, aFlag) NES aQuery A valid SQL query for the database aFlag Indicates whether the cursor can be updated

myConnection.cursor(aQuery)

329

JavaScript Programmer's Reference

These Cursor objects are used to run SQL queries against the database we are currently connected to. It is probably a good idea to consult the reference documentation for your database to fully understand how it handles cursors. See also:

Cursor object

Connection.execute() (Method) Execute some SQL on the database. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

Argument list:

someSQL

myConnection.execute(someSQL) A string containing valid SQL for the database

The SQL to be executed on the database is passed as an argument to this method.

Connection.majorErrorCode() (Method) Provide the code for an error raised by the database server or the ODBC interface to it. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

myConnection.majorErrorCode()

For a status code value of 5 when using the Oracle database, this yields a return code from the Oracle Call-level interface. For a status code value of 5 when using SQL server through the ODBC database interface, this yields the SQL server message number. For a status code value of 7 when using the Informix database, this yields the Informix error code. For a status code value of 7 when using the Sybase database, this yields the DB-Library error number. See also:

330

database.majorErrorCode(), DbPool.majorErrorCode(), Error handling, Status code

C – Connection.majorErrorMessage() (Method)

Connection.majorErrorMessage() (Method) Provide the descriptive text message for an error raised by the database server or by the ODBC interface to it. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

myConnection.majorErrorMessage()

For a status code value of 5 when using the Oracle database, this yields a text string describing the server error. For a status code value of 5 when using SQL server through the ODBC database interface, this yields a text string from SQL server. For a status code value of 7 when using the Informix database, this yields the text string from the vendor error library. For a status code value of 7 when using the Sybase database, this yields a text string from the DB-Library. See also:

database.majorErrorMessage(), DbPool.majorErrorMessage(), Error handling, Status code

Connection.minorErrorCode() (Method) Returns a supplementary error code for an error raised by the database server or the ODBC interface to it. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

myConnection.minorErrorCode()

For a status code value of 5 when using the Oracle database, this yields an operating system error code from the Oracle Call-level interface. For a status code value of 5 when using SQL server through the ODBC database interface, this yields the severity level from SQL server. For a status code value of 7 when using the Informix database, this yields the ISAM error code. For a status code value of 7 when using the Sybase database, this yields the severity level of the error from the DB-Library. See also:

database.minorErrorCode(), DbPool.minorErrorCode(), Error handling, Status code

331

JavaScript Programmer's Reference

Connection.minorErrorMessage() (Method) Returns a supplementary error message text for an error raised by the database server or the ODBC interface to it. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

myConnection.minorErrorMessage()

For a status code value of 5 when using the Oracle database, this yields the Oracle server name. For a status code value of 5 when using SQL server through the ODBC database interface, this yields the SQL server name. For a status code value of 7 when using the Informix database, this yields a text string describing the ISAM error. For a status code value of 7 when using the Sybase database, this yields the text of the operating system error from the DB-Library. See also:

database.minorErrorMessage(), DbPool.minorErrorMessage(), Error handling, Status code

Connection.prototype (Property) The prototype for the connection object that can be used to extend the interface for all connection objects. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

Connection object

JavaScript syntax:

NES

Connection.prototype

NES

myConnection.constructor.prototype

Refer to: prototype property

Connection.release() (Method) Releases this connection back into the pool for reuse. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

JavaScript syntax:

NES

332

myConnection.release()

C – Connection.rollbackTransaction() (Method)

There are a limited number of connections available for accessing the database. This is intentional. It prevents the database from being swamped by connections. The limit may be large or small depending on the scale of the database server and the software it is using. Requesting a connection from the DbPool object consumes one of the available connections. You must ensure that you release them back to the pool when you are finished, otherwise your server will soon use them all up and will be unable to form new connections to the database.

Connection.rollbackTransaction() (Method) A means of undoing transactions that have not yet been committed. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

JavaScript syntax:

NES

myConnection.rollbackTransaction()

Until you commit a transaction on the database, you can rollback to the previous commit state. Once you have committed a transaction, this opportunity to undo is lost. To undo after that, you must make changes under your own script's control. That means that if you anticipate that possibility, you will need to remember the previous values. On the whole, it's easier to let the database do this and to commit only when you are sure the transaction is complete and correct.

Connection.SQLTable() (Method) Create an HTML table as a result of a SQL query on the database. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

Argument list:

someSQL

myConnection.SQLTable(someSQL) A string containing valid SQL for the database

The argument to this method is a database query that is expected to yield some rows and columns. These are then reformatted with the requisite HTML tags to form a table. The table is likely to be fairly generic in appearance so you may need to modify the HTML that is returned or perhaps you could use style sheets to control its appearance.

Connection.storedProc() (Method) This method creates a Stproc object and then runs the stored procedure on the database server. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

333

JavaScript Programmer's Reference

JavaScript syntax:

NES

myConnection.storedProc(aProcName)

myConnection.storedProc(aProcName, aProcParm) aProcName The name of a stored procedure to call NES

Argument list:

aProcParm A parameter or parameters to pass to the stored procedure Stored procedures are pre-programmed code that lives inside the database. They generally encompass searches that are more complex than the simple select … from … where … SQL statements. Stored procedures in some database products cannot yield a record structure the same as a select query would. This is because they are not associated with any particular table and so they return the results as a resultset rather than a table record. You may need to do additional work to turn the resultset into the objects you need.

Warnings: Every middle-ware application server supports a completely different way of running stored procedures. At least it seems like that sometimes when you are using several different products. Fundamentally they all do the same thing but databases provide different mechanical implementations and so there are many different ways in which to develop code to exploit them.



See also:

Stproc object

Connection.toString() (Method) Returns a string containing a representation of the Connection object. Availability:

JavaScript – 1.2 Netscape Enterprise Server – 3.0

Property/method value type:

String primitive

JavaScript syntax:

NES

myConnection.toString()

The value of the object is converted to a string value that represents its value.

const (Reserved word) Reserved for future language enhancements. This keyword suggests that future standardization may support immutable constant values. This may allow stronger type casting of formal parameters in function prototypes. See also:

Function prototype, Reserved word, Type, volatile

Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3

334

C – Constant (Definition)

Constant (Definition) A literal description of a fixed value. A constant is a lexical element that represents a set numerical or string value. Numeric values can be integer or floating-point. String values may define only a single character but are nevertheless still considered to be a string. The Number and Math objects provide constant values as properties of the object class. These are static constants. Other static constants are provided by the implementation. For example the Event object supplies a set of masks in some implementations. These masks can be used to determine keyboard states. The DOM standard defines others as part of the event model. See also:

Character constant, Constant expression, Escape sequence (\), Floating constant, Integer constant, Lexical element, Literal, Math object, Number object, Primary expression, Variable

Cross-references: Wrox Instant JavaScript – page – 13

Constant expression (Definition) A constant expression is a combination of constants and an operator. A constant expression can always be degenerated to a simpler constant form. For example 100 + 101 is a constant expression, but could be replaced by the value 202. A constant expression involving strings is "abcdef" + "ABCDEF". This yields the result "abcdefABCDEF".

Warnings: ❑

In JavaScript you should always try to avoid the use of string concatenation unless you really have to use it. It is very useful. However, in Netscape and MSIE, over-using a string concatenation in a loop can lead to significant memory leaks. It is quite easy to leak several megabytes of memory in a few minutes simply by concatenating strings and passing them to a document.write(). The garbage does eventually get collected, but not until the page is refreshed. This means that a page that implements a ticker for instance can leak horribly until the page is refreshed. There are techniques you can employ to minimize this effect and you could trigger a garbage collection by reloading the page periodically under script control. See also:

Arithmetic constant, Character constant, Constant, Date constant, Escape sequence (\), Expression, Expression statement, Floating constant, Floating-point constant, Initialization, Integer constant, JavaScript language, Logical constant, Object constant

335

JavaScript Programmer's Reference

Constraint (Definition) A restriction placed on a script to be executed. A constraint determines a restriction that the syntax and semantics of the language must set upon the interpretation of the elements of the language. Violating these constraints should generate an interpretation error in a compliant implementation. See also:

Definition, Diagnostic message, Error handling

Construct (Property/internal) An object constructor call. Availability:

ECMAScript edition – 2

The internal constructor is invoked via the new operator. This is not implemented by all objects. Those that do support it are called constructor objects. In other languages these might be called factory objects.

Warnings: The global object does not have a Construct property and you cannot make copies of it with the new operator.



See also:

Constructor function, constructor property, Internal Method

Property attributes: DontEnum.

Cross-references: ECMA 262 edition 2 – section – 15 ECMA 262 edition 3 – section – 15.1.4

Constructor function (Definition) A function that can create new objects. Availability:

ECMAScript edition – 2

A constructor is analogous to a factory class in a truly object-oriented system. It instantiates new objects of its class by copying a built-in prototype object.

336

C – Constructor function (Definition)

A constructor function is a method that creates and initializes new objects or values. It is a way of calling the constructor object as a function rather than with the new operator. These constructor functions are available from the global object; the host implementation may add others for you to use: ❑

Object()



Function()



Array()



String()



Boolean()



Number()



Date()

Calling the constructor as a function is a way of carrying out type conversion. You can also create your own constructor functions. You name them with the name of the class you want to create. Depending on how you implement them, they may or may not work as type converting functions. When we use the new operator, it understands that the function is a constructor and as it constructs the new object, it associates the constructor function with it so you can locate it again, via the prototype and constructor properties. Because this function makes use of the 'this' keyword, it could be a method belonging to another object. However, it doesn't have to belong to an object to be used as a constructor in the first place. The object creation process will properly associate it in due course when it needs to. You don't need to pass parameters to add properties to objects as they are created. Constructors are generally a better way of making self documenting objects than simply instantiating more copies of the Object object. In addition, there is more opportunity to reuse and share code between multiple instances. It's probably not a good thing to add properties and methods to the base Object class as it means they would get inherited just about everywhere, because ultimately all prototype inheritance chains descend from the topmost Object. With a constructor, you can simulate arrays by making them from objects and property components. This may be useful if you want to run an array-based script in a very old JavaScript implementation although these days that likelihood of that is diminishing rapidly. The Netscape browser creates a constructor for virtually every object it instantiates. This can be an aid to debugging and making more flexible scripts. You can inspect an object by requesting its constructor property. This will normally convert to a string that contains the function definition and to determine the class it may be more useful to request the constructor.name property instead. This technique is not so useful in MSIE where constructors are only made available for objects that can genuinely be instantiated usefully by a script.

337

JavaScript Programmer's Reference

Example code: // This constructor function defines a class called Tree: function Tree(aName, aNode1, aNode2) { this.name = aName; this.leftbranch = aNode1; this.rightbranch = aNode2; } // We can now implement tree walking algorithms and // associate them with the prototype for the tree object: function tree_walk() { if((this.leftbranch == null) && (this.rightbranch == null)) { document.write(this.name); document.write("
"); } if(this.leftbranch != null) { document.write(this.name); document.write(" -L- "); this.leftbranch.walk(); } if(this.rightbranch != null) { document.write(this.name); document.write(" -R- "); this.rightbranch.walk(); } } // Now associate the tree walk with the prototype. Tree.prototype.walk = tree_walk; // Here we create a new tree object: // In this case, we have defined null values to signify we have reached // the end of the branching structure so we must be at a leaf node. myTree1 = new Tree("AAA", null, null); // Let's create another and join both to a third: myTree2 = new Tree("BBB", null, null); myTree3 = new Tree("CCC", myTree1, myTree2); // Now we walk the tree myTree3.walk(); // We could have created an array in the tree class and // stored more than two branches. B-Trees, Quad trees, // and Oct trees are all useful modelling tools for // building simulations.

See also:

338

Array simulation, Construct, constructor property, prototype property

C – constructor property (Definition)

Cross-references: ECMA 262 edition 2 – section – 4.3.4 ECMA 262 edition 2 – section – 15.1.3 ECMA 262 edition 3 – section – 4.3.4 Wrox Instant JavaScript – page – 31

constructor property (Definition) A reference to a constructor function. Availability:

ECMAScript edition – 2

A constructor property is a function object that creates and initializes new objects. Each constructor has an associated prototype object that provides inheritance and shared properties. There are constructor properties belonging to the Global object for all the Built-in (Native) object prototypes. These constructors are available as part of the core language from the global object. They are defined in the ECMA standard at editions 2 and 3. The host implementation may add others for you to use: ❑ ❑ ❑ ❑ ❑ ❑ ❑

Object() Function() Array() String() Boolean() Number() Date()

To create new objects, a new expression is formed with the constructor as its operand. The result is to create a new object by means of the constructor. For any object the constructor is a property of the prototype. The prototype is a property of the object and the constructor points back at the object. In that sense the prototype and constructor properties each point at the other's parent object. This needs to hold true for a constructor to be correctly set up: myObject.prototype.constructor is the same as: myObject They should test true with the === operator since they are supposed to be identical objects.

Warnings: ❑

Both Netscape and MSIE support a constructor property for the Math object. You won't find very many circumstances where you will need to create a new instance of the Math object. Note that the constructor is not a Math object but an Object object, therefore a new Math() statement will produce a new Object object and not a new Math object.

339

JavaScript Programmer's Reference



In both cases, attempting to execute a new Math() statement will cause a run-time error. Arguably, this is a bug because objects that should not be instantiated or cloned ought not to support a constructor so that you can sensibly write general-purpose routines that can test for the existence of a constructor property and can then exit gracefully if it is not supported.



The constructor property is supported so inconsistently across the browsers that this kind of test before use approach is almost impossible to deploy. See also:

Construct, Global object, prototype property

Cross-references: ECMA 262 edition 2 – section – 4.3.4 ECMA 262 edition 2 – section – 15.1.3 ECMA 262 edition 3 – section – 4.3.4

constructor.name (Definition) The name of the constructor that created an object. You can determine the class of an object by requesting the name property from its constructor. Since the constructor is a function, you are actually asking a function object for its name. Functions know all about their names. If you get the name of a function that's been used as a constructor, you have effectively gotten its class. Its type is still an object, but its class lets you tell one kind of object from another. See also:

Determining the object type

Content Model (Definition) A new model in the DOM level 3 specification describes how documents can be exchanged between implementations. The DOM level 3 content model is embodied in the following object classes: ❑

CMObject



CMExternalObject



CMNode



CMNodeList



NamedCMNodeMap



CMDataType



CMType



ElementDeclaration



ElementCMModel



AttributeDeclaration



EntityDeclaration

340

C – contextual() (Method)



DocumentCM



DomImplementationCM



ErrorHandler



NodeCM



TextCM

contextual() (Method) A JSS style control method. Availability:

JavaScript – 3.0 Netscape – 4.0 Deprecated

JavaScript syntax:

N

Argument list:

contextual(tags.anItem, ...).aProperty = aValue

anItem

A tag name such as P or B or H1

aProperty A style property of the returned tags object aValue A value to be stored in the property of the nominated tags This function can take a variable number of arguments, each one indicating a tag property within the tag's object. It is followed by a dot-delimited property value and basically provides a way to modify the same property across a large number of objects in a single call. This could be a quite useful function for a variety of other non-style-related cases. You may want to experiment and see whether, in your browser, the contextual() method is useful. However, it may only be present in Netscape browsers, thus limiting its usefulness for deployment. When used in a JSS context, this is more or less equivalent to H1 P { color: red }.

Warnings: ❑

This functionality is removed from Netscape 6.0.

Example code: // Set the color property for several objects at once. contextual(tags.P, tags.H1)color = "red";

See also:

JavaScript Style Sheets

Cross-references: Wrox Instant JavaScript – page – 50

341

JavaScript Programmer's Reference

continue (Statement) Force the next iteration of a loop. Availability:

JavaScript syntax:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.0 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0 continue aLabelName; -

Argument list:

continue;

aLabelName

The name of a label associated with some code

The continue keyword is a jump statement. It is used in an iterator loop to proceed to the next cycle without executing the remaining lines in the statement block. A continue statement can only legally exist inside a while or for loop in an ECMA-compliant implementation. Implementations that provide additional iterator types may also honor the same behavior for the continue statement. The continue statement would normally be executed conditionally, otherwise it would cause the remaining lines to be redundant since no execution flow would ever reach them. Compilers generally warn you about this, but JavaScript would likely simply ignore it. The continue statement is obeyed by the smallest enclosing iterator loop. At version 1.2 of JavaScript, the continue statement was enhanced to support a label as a continuing destination. When the continue is processed, it will jump to the start of the statement that has been labeled. If an iterator is labeled, then the continue is associated with that iterator. This mechanism can only be used in a while, for or for ... in loop. A labeled continue behaves differently according to the iterator it has been used in.

Warnings: ❑

In Netscape 4, there is a bug with labeled continue statements and do ... while loops that causes the continue to vector to the top of the loop without testing the condition. This can set up an endless loop. You could work round this by creating a while loop and modifying the test condition.



When the continue statement is used, its behavior inside a while loop suggests that a while loop is not exactly similar to a for loop. In a while loop, it simply runs the test condition again before deciding to loop or not. In a for loop, the incrementor gets executed again and then the test condition. You cannot perfectly simulate a for loop with a while loop if a continue statement is involved. See also:

342

break, Completion type, do ... while( ... ), for( ... ) ..., for( ... in ... ) ..., Iteration statement, Jump statement, Label, return, Scope chain, Statement, while( ... ) ...

C – Control character (Definition)

Cross-references: ECMA 262 edition 2 – section – 10.1.4 ECMA 262 edition 2 – section – 12.7 ECMA 262 edition 3 – section – 10.1.4 ECMA 262 edition 3 – section – 12.7 Wrox Instant JavaScript – page – 25

Control character (Definition) A non-printing character entity. A control character is any character code point in the locale-specific character set that does not print a visible glyph when it is output. See also:

ASCII, Character handling, isCtrl(), isGraph(), isPrint(), Printing character, Unicode

Conversion (Definition) Changing the type of a value, object, function or constant. Values are continuously being changed from one type of value to another inside a JavaScript interpreter. The very nature of its weak data typing and the automatic promotion and demotion of values in expressions causes implicit changes in the type of values at almost every step of a script's execution. The conversion behavior of each type is discussed in the coverage of each of the Native primitive types that are built into the interpreter. Refer to the Cast operator description as well for further information. There are also some internal conversion operators that provide the basic underlying conversion facilities. These are described in the following topics: ❑

ToBoolean



ToInt32



ToInteger



ToNumber



ToObject



ToPrimitive



ToString



toString()



ToUint16



ToUint32

343

JavaScript Programmer's Reference

These are given individual topics on account of their description in the ECMA standard. There are however four basic and fundamental conversions. These are: ❑

Boolean



Number



String



Object

The internal function topics cover what happens inside an interpreter. In this topic and the several following, we are concerned with the script visible effects of conversion. There are some circumstances where the conversion of an object to a number or a string can be ambiguous. The cases of concatenate or add and the relative expression operators are such an example. The Date objects will prefer to be converted to a string rather than a number if at all possible and consistent with the context. Many objects have toString() methods. Not as many will support the valueOf() method. The valueOf() method is so named because it is not implicitly a toNumber() method. It may return a string because that is the most reasonable primitive. It is really a toPrimitive() method. See also:

Argument, Cast operator, Integer constant, Integer promotion, LValue, ToBoolean, ToInt32, ToInteger, ToNumber, ToObject, ToPrimitive, ToString, toString(), ToUint16, ToUint32

Conversion to a Boolean (Definition) Converting values to a Boolean representation. There are three conversions to study. Obviously Boolean values will remain as they are. This table summarizes the effects of converting values to Boolean: Value:

Boolean equivalent:

null Undefined value Non empty string Empty string 0 NaN Infinity Negative infinity Any other non zero number Object Array Function

false false true false false false true true true true

344

No direct boolean equivalent true

C – Conversion to a number (Definition)

There is no proper Boolean equivalent for an array. The ECMA standard does not address this either. The standard does suggest that any non-null object reference convert to true and since an array is an object, it should rightly become a true value.

Warnings: ❑

Some non-portable behavior has been implemented in the MSIE and Netscape browsers. In some cases, the array becomes true in all cases. In others, a non-empty array is true, while an empty array is false. This seems to be based on the length value.



You should test your target browsers to see what behavior persists if you intend to use this capability and not rely on any implicit array conversion facilities. It is probably safest to implement your own conversion method.



The array to Boolean conversion is so inconsistently supported as to render it unusable in any crossbrowser implementation.



A more insidious side effect is exhibited by the fact that all objects convert to the Boolean true value, even a Boolean object whose value is false. This is demonstrated in the example. You really need to be careful if you are storing Boolean values in objects rather than simple variables, especially if they are driving some conditional code execution.

Example code:





0000





See also:

Property

Broken down time, Browser version compatibility, Calendar time, Compatibility strategies, Date.Class, Date.length, Date.prototype, Event.timeStamp, java.util.Date, JellyScript, MakeDate(), MakeDay(), MakeTime(), Native object, Object object, Time range, Time value, TimeClip(), unwatch(), watch() JavaScript

JScript

N

IE

Opera

NES

ECMA

Notes

constructor

1.1 +

1.0 +

3.0 +

3.02 +

-

-

2+

-

length

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

ReadOnly, DontEnum.

prototype

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

2.0 +

2+

ReadOnly, DontDelete, DontEnum.

Method

JavaScript

JScript

N

IE

Opera

NES

ECMA

Notes

getDate()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getDay()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getFullYear()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getHours()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getMilliseconds()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getMinutes()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getMonth()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getSeconds()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getTime()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

getTimezoneOffset()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

Warning

getUTCDate()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getUTCDay()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getUTCFullYear()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

Warning

getUTCHours()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getUTCMilliseconds()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getUTCMinutes()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getUTCMonth()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getUTCSeconds()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

getVarDate()

-

3.0 +

-

4.0 +

-

-

-

-

getYear()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

Warning, Deprecated

Table continued on following page

384

D – Date object (Object/core)

Method

JavaScript

JScript

N

IE

Opera

NES

ECMA

Notes

parse()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setDate()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setFullYear()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setHours()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setMilliseconds()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setMinutes()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setMonth()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setSeconds()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setTime()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

setUTCDate()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setUTCFullYear()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setUTCHours()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setUTCMilliseconds()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setUTCMinutes()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setUTCMonth()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setUTCSeconds()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

setYear()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

Warning, Deprecated

toDateString()

1.5 +

5.5 +

6.0 +

5.5 +

-

-

3+

-

toGMTString()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

Warning, Deprecated

toLocaleDateString()

1.5 +

5.5 +

6.0 +

5.5 +

-

-

3+

-

toLocaleString()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

-

toLocaleTimeString()

1.5 +

5.5 +

6.0 +

5.5 +

-

-

3+

-

toSource()

1.3 +

3.0 +

4.06 + 4.0 +

-

-

3+

-

toString()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

2+

Warning

toTimeString()

1.5 +

5.5 +

6.0 +

5.5 +

-

-

3+

-

toUTCString()

1.2 +

3.0 +

4.0 +

4.0 +

-

-

2+

-

valueOf()

1.1 +

3.0 +

3.0 +

4.0 +

-

-

2+

-

Cross-references: ECMA 262 edition 2 – section – 10.1.5 ECMA 262 edition 2 – section – 15.9 ECMA 262 edition 2 – section – 15.9.6 ECMA 262 edition 3 – section – 10.1.5 ECMA 262 edition 3 – section – 15.9 O'Reilly JavaScript Definitive Guide – page – 48

385

JavaScript Programmer's Reference

Date() (Constructor) A Date object constructor. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0

Property/method value type:

Date object

JavaScript syntax:

-

new Date()

-

new Date(aValue)

-

new Date(aYear, aMonth)

-

new Date(aYear, aMonth, aDate)

-

new Date(aYear, aMonth, aDate, anHour)

-

new Date(aYear, aMonth, aDate, anHour, aMinute) new Date(aYear, aMonth, aDate, anHour, aMinute, aSecond) new Date(aYear, aMonth, aDate, anHour, aMinute, aSecond, aMillisecond)

JavaScript syntax:

Argument list:

aDate

An optional date within the month value

aMillisecond

An optional value between 0 and 999 milliseconds

aMinute

An optional value between 0 and 59 minutes

aMonth

An optional 0 to 11 month value

anHour

A value between 0 and 23 hours

aSecond

An optional value between 0 and 59 seconds

aYear

A full year value

aValue

A time in UTC milliseconds

The result of calling this constructor is a date object with the indicated date and time value. Calling the Date() constructor with the new operator creates a fresh object based on the Date prototype. The value of this new Date object depends on the parameters specified when the constructor was invoked. This is not the same as simply calling the Date() function which would yield the current system date and time at the instant it was called. The arguments to the Date() constructor are all optional, but they are also positional. This means that you must mark empty positions with comma separated null values to indicate that a parameter needs to be skipped. The time values are assumed to be measured in local time and not UTC. The prototype of the new Date object is the built in Date prototype object.

386

D – Date() (Constructor) Functionally, the algorithm that manufactures a new date value uses the internal MakeDay(), MakeTime(), and MakeDate() functions that we describe elsewhere. If the year value is less than 99, then the date creation adds 1900 to it and assumes the date is in the 20th century. To avoid millennium problems, always specify a full year number. The following rules apply where items are omitted from the right of the argument list. Zero values are assumed for hours, minutes and seconds. When all three are missing, the time is assumed to be midnight. The date value is assumed to be the first of the month, and the default month is not considered since a single value on its own is taken to mean a millisecond time value in UTC time coordinates. When all arguments are omitted, the time value for the new object is set to the current time in UTC time coordinates. Putting null values in place of the year month and date sets the time correctly but unpredictable date values are substituted.

Example code:





See also:

Constructor function, constructor property, Date constant, Date()function, Date.UTC(), Global object, MakeDate(), MakeDay(), MakeTime(), new, Object constant, TimeClip()

387

JavaScript Programmer's Reference

Cross-references: ECMA 262 edition 2 – section – 15.1.3.7 ECMA 262 edition 2 – section – 15.9.3 ECMA 262 edition 2 – section – 15.9.4 ECMA 262 edition 3 – section – 15.9.3

Date() (Function) A function that returns the current date. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0

Property/method value type:

String primitive

JavaScript syntax:

-

Date()

This function returns a string primitive representing the current UTC time value. When the Date() constructor is called as a function rather than in a new expression, it returns a string representing the current time (in UTC time). Note that when calling it as a function the arguments are all ignored and it is not equivalent to calling the Date() constructor in a new expression at all. Effectively, the function call to a Date() constructor behaves as if you had coded this fragment of JavaScript in the script source text: (new Date()).toString() See also:

Cast operator, Constructor function, constructor property, Date constant, Date() constructor, Implicit conversion

Cross-references: ECMA 262 edition 2 – section – 15.1.3.7 ECMA 262 edition 2 – section – 15.9.2 ECMA 262 edition 3 – section – 15.9.2

Date.Class (Property/internal) Internal property that returns an object class. Availability:

388

ECMAScript edition – 2

D – Date.constructor (Property) This is an internal property that describes the class that a Date object instance is a member of. The reserved words suggest that, in the future, this property may be externalized. See also:

Class, Date object

Property attributes: DontEnum, Internal.

Cross-references: ECMA 262 edition 2 – section – 8.6.2 ECMA 262 edition 2 – section – 15.9.3.1 ECMA 262 edition 3 – section – 8.6.2

Date.constructor (Property) A reference to a constructor object. Availability:

ECMAScript edition – 2 JavaScript – 1.1 JScript – 1.0 Internet Explorer – 3.02 Netscape – 3.0

Property/method value type:

Date constructor object

JavaScript syntax:

-

Date.constructor

The initial value of the date prototype constructor is the built-in Date constructor. You can use this as one way of creating Date objects although it is more popular to use the new Date() technique. This property is useful if you have an object that you want to clone but you don't know what sort of object it is. Simply access the constructor belonging to the object you have a reference to. Netscape provides constructors for many objects, virtually all of them in fact, even when it is highly inappropriate to do so. MSIE is far more selective and there are some occasions when you might wish for a constructor that MSIE does not make available. See also:

Date constant, Date.length, Date.parse(), Date.prototype, Date.UTC()

Cross-references: ECMA 262 edition 2 – section – 15.9.5.1 ECMA 262 edition 3 – section – 15.9.3

389

JavaScript Programmer's Reference

Date.getDate() (Method) Returns the day number within a month for a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getDate()

This method returns a day number within a month from the date value of the receiving object. The value is 1 based and will not exceed 31 although the range is variable based on month and leap year contexts. The date is computed according to local time coordinates.

Example code:





See also:

Date.prototype, Date.setDate()

Cross-references: ECMA 262 edition 2 – section – 15.9.5.10 ECMA 262 edition 3 – section – 15.9.5.14

390

D – Date.getDay() (Method)

Date.getDay() (Method) Returns the weekday number for a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getDay()

A weekday number for the date value of the receiving object is returned. The value will be in the range 0 to 6, with 0 representing Sunday. The value is computed according to Local time coordinates.

Example code:





See also:

Date.prototype

Cross-references: ECMA 262 edition 2 – section – 15.9.5.12 ECMA 262 edition 3 – section – 15.9.5.16

391

JavaScript Programmer's Reference

Date.getFullYear() (Method) Returns the full year for a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.3 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getFullYear()

The full year number of the date value in the receiving object is returned as a four digit value. This is much preferred to the getYear() method which suffers from Y2K ambiguities and is now deprecated in favor of this method. The year number is a local time value.

Example code:





See also:

Date.getYear(), Date.prototype, Date.setFullYear(), Date.setUTCFullYear(), Date.setYear()

Cross-references: ECMA 262 edition 2 – section – 15.9.5.6 ECMA 262 edition 3 – section – 15.9.5.10

392

D – Date.getHours() (Method)

Date.getHours() (Method) Returns the hour value for a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getHours()

The hours of the time value contained in the receiving object. This is returned as an integer in the range 0 to 23 inclusive. The value is computed according to local time coordinates.

Example code:





See also:

Date.prototype, Date.setHours(), Date.setUTCHours()

Cross-references: ECMA 262 edition 2 – section – 15.9.5.14 ECMA 262 edition 3 – section – 15.9.5.18

393

JavaScript Programmer's Reference

Date.getMilliseconds() (Method) Return the milliseconds value of a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getMilliseconds()

The milliseconds of the time value contained in the receiving object. The result will be an integer in the range 0 to 999 inclusive. The value is computed according to local time coordinates. In the example a timer is set up to trigger a function call every 1000 milliseconds. However, processing load may affect how accurately the timer is executed. By measuring the time on each call, we know that the millisecond value should be the same each time but you will probably observe a small and random perturbation in the value. You can compensate for this by making a small adjustment to the timer value to take this error into account. You will most likely need to reduce the value 1000 by a few milliseconds to get a more accurate timer.

Example code:

000



See also:

394

Date.prototype, Date.setMilliseconds(), Date.setUTCMilliseconds()

D – Date.getMinutes() (Method)

Cross-references: ECMA 262 edition 2 – section – 15.9.5.20 ECMA 262 edition 3 – section – 15.9.5.24

Date.getMinutes() (Method) Returns the minutes value of a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getMinutes()

The minutes of the time value contained in the receiving object. The result will be an integer in the range 0 to 59 inclusive. The value is computed according to local time coordinates.

Example code:







See also:

Date.prototype, Date.setSeconds(), Date.setUTCSeconds()

Cross-references: ECMA 262 edition 2 – section – 15.9.5.18 ECMA 262 edition 3 – section – 15.9.5.22

Date.getTime() (Method) Returns the time value of a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

Property/method value type:

Time value

JavaScript syntax:

-

myDate.getTime()

The time value of the receiving object. This will be an integer that represents the time in milliseconds since the time origin at midnight on January the first, 1970. This method returns the time value of the receiving object.

398

D – Date.getTimezoneOffset() (Method)

Example code:







See also:

Date.prototype, Date.setUTCMinutes()

Cross-references: ECMA 262 edition 2 – section – 15.9.5.17 ECMA 262 edition 3 – section – 15.9.5.21

406

D – Date.getUTCMonth() (Method)

Date.getUTCMonth() (Method) Returns the UTC month number for a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.3 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getUTCMonth()

The result of this method is month number for the receiving date object. The value will be in the range 0 to 11 inclusive, with the value 0 representing January, and 11 representing December. The month number is measured in UTC time coordinates.

Example code:





See also:

Date.prototype, Date.setUTCMonth()

Cross-references: ECMA 262 edition 2 – section – 15.5.9.9 ECMA 262 edition 3 – section – 15.9.5.13

407

JavaScript Programmer's Reference

Date.getUTCSeconds() (Method) Returns the UTC seconds value for a date/time. Availability:

ECMAScript edition – 2 JavaScript – 1.3 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myDate.getUTCSeconds()

The result of this method is the seconds part of the time value contained in the receiving object. The value will be in the range 0 to 59 inclusive. The value is computed according to UTC time coordinates.

Example code:



--------------------------------------------------------------

See also:

COMMENT object, Pitfalls

Cross-references: Wrox Instant JavaScript - page 46

Hierarchy of objects (Definition) To fully understand JavaScript and in particular its use in the browser, it is helpful to know how objects relate to one another. In the core JavaScript language, objects are related to one another by means of the prototype chain. This is a hierarchy that determines the inheritance of functionality from a super-class, although it's an object-based inheritance and not really a class-based inheritance. You can only walk up this hierarchy. There is no convenient way to determine what objects are sub-classed from an object. From version 5.0 of MSIE and version 6.0 of Netscape, there are several hierarchy models available for traversing the document. The HTML view of the document is not quite the same as the DOM view. In general, each one is based on a property to traverse up the tree to a parent and collections for traversing down the tree to the leaf nodes. Here are some examples of the different hierarchical arrangements. ❑

The parentElement and children[] collection operate on the HTML tag-based hierarchy.



The parentNode property and childNodes[] collection can be used to traverse the DOM hierarchy which exposes the interstitial text objects between the HTML tags. These are not visible to the HTML view.



The spatial layout and positioning of objects relative to one another can be walked upwards by means of the offsetParent property. You can't traverse this tree from top to bottom without inspecting the contents of the children[] collection and looking at each child's offsetX and offsetY properties.

1022

H – Hierarchy of objects (Definition)



The all[] collection flattens the whole tree from the receiving object downwards. The document.all[] collection is the complete tree. This can slow things down if you are searching it to find a single object.



An editing hierarchy is constructed with the parentTextEdit property which describes the relationship between items that can have a text range created for them, and hence have some selectable content that can be cut or copied to the clipboard (usually as text).



Function calls construct a hierarchy by means of the Argument objects which link upwards to the calling function's Arguments object. This provides a way to walk through a stack trace to diagnose a calling sequence.



You can create custom hierarchies by using nested tags and navigating them by means of the corresponding DIV objects they instantiate.



A spatial hierarchy is created in Netscape version 4 with the tags. Layers sharing a common parent are siblings and can be ordered relative to one another.



A CSS style hierarchy is implemented in MSIE to describe the relationship between CSS style rule objects and their owning parent style sheet.



Another hierarchy can be built by importing style sheets into one another to allow styles to be managed in a more modular fashion. This is also supported at the rule level by means of the styleSheet.addRule() method.

The DOM level 2 standard adds a suite of traversal methods for walking through a document object model. It is embodied in the following classes: ❑

NodeIterator



NodeFilter



TreeWalker



DocumentTraversal

Related to the traversal suite, the DOM level 2 standard also introduces the Range suite. This is embodied in these classes: ❑

Range



DocumentRange



RangeException See also:

Arguments.caller, ChildNodes object, DIV object, Document.createTextNode(), Element.all[], Element.childNodes[], Element.children[], Element.offsetParent, Element.ownerDocument, Element.parentElement, Element.parentNode, Element.parentTextEdit, Layer.siblingAbove, Prototype Based Inheritance, rule.parentStyleSheet, StyleSheet.addImport(), StyleSheet.addRule(), StyleSheet.owningElement, StyleSheet.owningNode, StyleSheet.parentStyleSheet

1023

JavaScript Programmer's Reference

High order bit (Definition) The most significant bit in an integer value.

1

See also:

1

1

1

1

0

0

0

Bit, Bit-field, Bitwise operator, byte

History (Background) Scripting language history. Availability:

ECMAScript edition - 2

The JavaScript language was invented by Brendan Eich at Netscape. In the early days, it was known as LiveScript. The ECMA 262 standard is based on the earlier work at Netscape where they embedded the JavaScript interpreter into the Netscape version 2.0 web browser. Microsoft also embedded scriptdriven capabilities into their version 3.0 of the MSIE browser. The Microsoft interpreter implements a language called JScript as opposed to JavaScript. Microsoft clearly chose not to use the word JavaScript. It might be because any product name containing the word 'Java' needs to be licensed from Sun Microsystems or that it was a Netscape originated name. Given the very public antagonism between Microsoft and the other two, this is understandable. Perhaps it also gives Microsoft a little extra leeway to extend the language in non-standard ways. Both Microsoft and Netscape have continued to enhance their implementations in subsequent versions of their web browsers, taking them sometimes in completely opposing directions. In November 1996, the language started to become standardized by a working group under the ECMA organization. At this stage it was also commonly referred to as ECMAScript and became a published standard in June 1997. By April 1998, the ECMA 262 standard had been adopted as an international standard as ISO/IEC 16262 which prompted a second edition of the ECMA standard to keep the two fully aligned. A third edition of the ECMA 262 standard was published in October 1999. On the horizon are upgraded interpreters from Netscape and Microsoft, and the availability of JavaScript in a variety of other products such as TV set-top boxes, mobile phones and embeddings into legacy applications. See also:

1024

JavaScript language, JavaScript version, JScript version

H – history (Property)

Cross-references: ECMA 262 edition 2 - section Introduction ECMA 262 edition 3 - section Introduction Wrox Instant JavaScript - page 3

history (Property) An alias to the window.history property. Availability:

JavaScript - 1.1 JScript - 3.0 Internet Explorer - 4.0 Netscape - 3.0 Opera - 3.0

Property/method value type:

History object

JavaScript syntax:

-

history myWindow.history

Property attributes: ReadOnly.

Refer to: Window.history

History object (Object/browser) A history object owned by the window. This exposes information about URLs that have been visited previously. Availability:

JavaScript syntax:

JavaScript - 1.0 JScript - 1.0 Internet Explorer - 3.02 Netscape - 2.0 Opera - 3.0 -

myHistory = history

-

myHistory = myWindow.history

Object properties:

current, length, next, previous

Object methods:

back(), forward(), go()

1025

JavaScript Programmer's Reference

Netscape version 4 provides access to the history array by signed scripts. Earlier versions of Netscape and MSIE do not provide this level of access and therefore the history object is limited in what you can do with it. Some properties can be accessed by non-privileged scripts. In Netscape, each element in the History object array is a String containing the URL for that item in the history. In MSIE, the objects are not accessible directly.

Warnings: ❑

The array elements and properties of this object cannot be accessed by JavaScript unless the script has the UniversalBrowserRead privilege granted to it.



On Netscape, the toString() method is not correctly implemented and returns the value "[object]" instead of "[object History]". Collection object, UniversalBrowserAccess, UniversalBrowserRead, Window.history

See also:

Property

JavaScript

JScript

N

IE

Opera

HTML

Notes

current

1.1 +

-

3.0 +

-

3.0 +

-

Warning, ReadOnly.

length

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

-

ReadOnly.

next

1.1 +

-

3.0 +

-

3.0 +

-

Warning, ReadOnly.

previous

1.1 +

-

3.0 +

-

3.0 +

-

Warning, ReadOnly.

Method

JavaScript

JScript

N

IE

Opera

HTML

Notes

back()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

-

-

forward()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

-

-

go()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

-

Warning

History.back() (Method) Go to the previous page. Availability:

JavaScript - 1.0 JScript - 1.0 Internet Explorer - 3.02 Netscape - 2.0 Opera - 3.0

JavaScript syntax:

-

This is accessible to unsigned scripts. See also:

1026

Window.back()

myHistory.back()

H – History.current (Property)

History.current (Property) The URL of the current window content. Availability:

JavaScript - 1.1 Netscape Navigator - 3.0 Opera browser - 3.0

Property/method value type:

String primitive

JavaScript syntax:

N

myHistory.current

If you are accessing the URL of the current page, it is probably better to use the location object and access its href property.

Warnings: ❑

The UniversalBrowserRead privilege is required to access this property value. See also:

UniversalBrowserRead

Property attributes: ReadOnly.

History.forward() (Method) Go to the next page. Availability:

JavaScript - 1.0 JScript - 1.0 Internet Explorer - 3.02 Netscape - 2.0 Opera - 3.0

JavaScript syntax:

-

myHistory.forward()

This is accessible to unsigned scripts. See also:

Window.forward()

1027

JavaScript Programmer's Reference

History.go() (Method) Return to a URL from the history array. Availability:

JavaScript - 1.0 JScript - 1.0 Internet Explorer - 3.02 Netscape - 2.0 Opera browser - 3.0

JavaScript syntax:

-

myHistory.go(anIndex)

-

myHistory.go(aURL)

anIndex

myHistory.go(aDocTitle)

aURL

A URL value to go to

aDocTitle

The name of a document (in Netscape)

Argument list:

Denotes which history item to go to

You can perform a soft reload of a page, retaining its current settings by means of the History.go(0) method call. The following values are meaningful as an argument: ❑

-4 indicates you want to go back 4 pages.



-1 indicates you want to go back one page.



0 requests a reload of the current page



2 indicates you want to go forward two pages



A URL indicates a specific page to load



A Document title references the history list associatively

Warnings: ❑

There are some bugs in this method in versions of Netscape prior to version 4. MSIE version 3 also exhibits unruly behavior.

Example code: // Recall a page from the history keeping form settings intact history.go(-1);

See also:

1028

Location.reload()

H – History.length (Property)

History.length (Property) The number of history entries available. Availability:

JavaScript - 1.0 JScript - 1.0 Internet Explorer - 3.02 Netscape - 2.0 Opera - 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myHistory.length

Property attributes: ReadOnly.

Refer to: Collection.length

History.next (Property) The next document in the history array. Availability:

JavaScript - 1.1 Netscape - 3.0 Opera - 3.0

Property/method value type:

String primitive

JavaScript syntax:

N

myHistory.next

The value you get back from this property will depend very much on what navigation the user has recently performed. Most of the time this would yield a null or undefined value unless the user has used the [BACK] button.

Warnings: ❑

The UniversalBrowserRead privilege is required to access this property value.



This property is not supported on the WebTV platform. See also:

JellyScript, UniversalPreferencesRead

Property attributes: ReadOnly.

1029

JavaScript Programmer's Reference

History.previous (Property) The previous document in the history array. Availability:

JavaScript - 1.1 Netscape - 3.0 Opera - 3.0

Property/method value type:

String primitive

JavaScript syntax:

N

myHistory.previous

You may find it more useful to build a stack of pages visited in a persistent array. This can be tricky within a single window, but if you are prepared to use a frameset, you can create a global session store for such things. That way you'd be able to traverse a logical history rather than the possibly random page ordering that the user navigated.

Warnings: ❑

The UniversalBrowserRead privilege is required to access this property value. See also:

UniversalPreferencesRead

Property attributes: ReadOnly.

H object (Object/HTML) An object that represents the to tags. Availability:

DOM level - 1 JavaScript - 1.5 JScript - 3.0 Internet Explorer - 4.0 Netscape - 6.0

Inherits from:

Element object

JavaScript syntax:

IE

myH1 = myDocument.all.anElementID

IE

myH1 = myDocument.all.tags("H1")[anIndex]

IE

myH1 = myDocument.all[aName]

-

myH1 = myDocument.getElementById(anElementID) myH1 = myDocument.getElementsByName (aName)[anIndex] myH1 = myDocument.getElementsByTagName ("H1")[anIndex]

-

1030

H – H object (Object/HTML)

HTML syntax: Argument list:

... , ... , ... , ... , ... , ... anIndex A reference to an element in a collection aName

An associative array reference

anElementID

The ID value of an Element object

Object properties:

align

Event handlers:

onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

The properties, methods, collections and event handling support for the tag object are also provided for through tag objects as well. It is only necessary to document one of these object classes, although the other header types are each instantiated as objects of an appropriately named class in MSIE. The syntax examples illustrate the use of an tag object. The through tags are block-level tags. That means that they force a line break before and after themselves. The DOM level 1 specification refers to this and its sibling object types as a HeadingElement object. See also:

Element object

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

align

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick onDblClick onDragStart onFilterChange onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart

1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + -

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + -

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + -

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

Inheritance chain: Element object, Node object

1031

JavaScript Programmer's Reference

H.align (Property) The alignment of an to tag. Availability:

DOM level - 1 JavaScript - 1.5 JScript - 3.0 Internet Explorer - 4.0 Netscape - 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myH1.align

The alignment of the H1 (to H6) object with respect to its containing parent object is defined in this property. The following set of alignment specifiers are available: ❑

absbottom



absmiddle



baseline



bottom



center



left



middle



right



texttop



top

home() (Method) Go to the home page according to the user preferences. Availability:

JavaScript - 1.2 Netscape - 4.0

Property/method value type:

undefined

JavaScript syntax:

Refer to: Window.home()

1032

N N

home() myWindow.home()

H – Host environment (Definition)

Host environment (Definition) The environment in which a JavaScript interpreter has been embedded. The host environment is where the JavaScript interpreter lives. Typically this might be a web browser, a web server back end, or an embedded implementation. There are other possibilities as well, limited only by the imagination of the software developers and their ingenuity in finding new ways to apply JavaScript. JavaScript is usually interpreted. However, recent digital TV systems are deploying byte code compiled JavaScript and it is also being used in that way for mobile devices. See also:



See also:

ASCII, Associativity, Equal to (==), Equality expression, Equality operator, Greater than (>), Greater than or equal to (>=), Identity operator, JellyScript, Less than ( characters, which explains why we couldn't see it. The web browser thought it was a tag and didn't recognize it so it was hidden.



The second piece of example code shows how the properties were enumerated and how to display the hidden property name.

Example code: // Output some text to the Java console java.lang.System.out.println("Some text message"); // Create a JavaScript object that encapsulates a Java Objectvar

1203

JavaScript Programmer's Reference

myJavaDateObject = new Packages.java.util.Date; -------------------------------------------------------------

See also:

captureEvents(), Event, Event names, Event type constants, Event.modifiers, Event.which, onKeyDown, onKeyPress, onKeyUp, String.fromCharCode()

Keyword (Definition) The keywords that ECMAScript defines should be avoided when you create your own identifier or variable names. A keyword is a word that has special significance in the JavaScript language. It follows the rules that ECMA lays down for describing identifiers. All of the JavaScript keywords are reserved and define the language syntax. You must not use any of them as identifier names for variables, properties, methods and functions that you define. ECMAScript reserves a set of keywords for future use. These are intended to make provision for future language features and to give developers warning that they should avoid using these keywords in order that their scripts should continue to operate when the language is revised. Other special names are defined by JavaScript to identify properties of the Global object and constructor functions of the built-in data types. You should avoid these too, unless you are intentionally overriding their functionality with your own.

1276

Error! No text of specified style in document.

Here is a list of keywords that ECMA edition 2 mandates a compliant implementation should support: ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑ ❑

break continue delete else for function if in new return this typeof var void while with

In addition, these are constants that should also be avoided: ❑

true



false



null

The third edition of the ECMA standard adds these keywords which in the earlier edition were reserved for future use: ❑

case



catch



default



do



finally



instanceof



switch



throw



try

1277

Chapter number

The remaining reserved keywords as of edition 3 are: ❑

abstract



boolean



byte



char



class



const



debugger



double



enum



export



extends



final



float



goto



implements



import



int



interface



long



native



package



private



protected



public



short



static



super



synchronized



throws



transient



volatile

However, you should note that Netscape anticipates a future standard and supports these already: ❑

export



import

1278

Error! No text of specified style in document.

The JavaScript 2.0 project defines these which should also be avoided and which will likely be added to a later edition of the ECMAScript standard: ❑

namespace



use

Many implementations of JavaScript will introduce additional keywords. Some will provide functional behavior for the reserved keywords. To remain ECMAScript compliant, the reserved words specified in edition 3 must be supported sufficiently to prevent parsing errors, but need not provide any meaningful functionality. You can code defensively to avoid any future problems. Using an underscore character or digit in your identifier names should improve the chances of your script continuing to operate properly in later versions of the language. Using upper case may help, but is less of a guarantee of safety. In particular, you should be very careful to avoid the names of properties and methods belonging to the Global object. See also:

Lexical element, Reserved word, Token

Cross-references: ECMA 262 edition 2 – section – 7.4.2 ECMA 262 edition 3 – section – 7.5.2

1279

Label (Definition) An identifier marking a section of code. Availability:

ECMAScript edition –3

In JavaScript version 1.2, the case and default labels were added, which introduced as a byproduct the fact that any fragment of code can be labelled with an identifier. The identifier can be any legal JavaScript identifier that does not match a reserved keyword. The namespace that labels exist in, is separate to that of variables and function names. This means you can use the same identifier names over again, although it’s probably good practice not to. Adding a label in front of an iterator allows you to associate a label name with a break or continue statement. This means that you can break or continue nested iterators from deep inside them. This can greatly simplify the logic of a looping system. If the goto keyword is ever implemented, it would depend on this labelling mechanism being extended to provide a useful destination.

Example code: // An example break to a labelled line outerLoop: for (var i=0; i ), Greater than or equal to (>=), Identically equal to (===), Less than (

Bitwise shift right

L-R

>>>

Bitwise shift right (unsigned)

L-R


=

Compare greater than or equal to

L-R

in

Property is in object

L-R

instanceof

Object is instance of another object

L-R

==

Compare equal to

L-R

!=

Compare NOT equal to

L-R

===

Compare identically equal to

L-R

!==

Compare identically NOT equal to

L-R

&

Bitwise AND

L-R

^

Bitwise XOR

L-R

|

Bitwise OR

L-R

&&

Logical AND

L-R

||

Logical OR

L-R

?:

Conditional execution

R-L

=

Assign

R-L

*=

Multiply and assign

R-L

/=

Divide and assign

R-L

%=

Remainder and assign

R-L

+=

Add and assign

R-L

-=

Subtract and assign

R-L

=

Bitwise shift right and assign

R-L

>>>=

Bitwise shift right (unsigned) and assign

R-L

&=

Bitwise AND and assign

R-L

|=

Bitwise inclusive OR and assign

R-L

^=

Bitwise XOR and assign

R-L

,

Argument delimiter

L-R

;

Empty statement

L-R

{ }

Delimit code block

L-R

1661

JavaScript Programmer's Reference

Associativity, Object property delimiter (.), Primary expression

See also:

Cross-references: ECMA 262 edition 2 – section 11.1.4 ECMA 262 edition 3 – section 11.1.6

OptGroupElement object (Object/HTML) A means of grouping options together into logical sets. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Inherits from:

Element object

JavaScript syntax:

IE IE IE -

myOPTGROUP = myDocument.all.anElementID myOPTGROUP = myDocument.all.tags("OPTGROUP") [anIndex] myOPTGROUP = myDocument.all[aName] myOPTGROUP = myDocument.getElementById(anElementID) myOPTGROUP = myDocument.getElementsByName (aName)[anIndex] myOPTGROUP = myDocument.getElementsByTagName ("OPTGROUP")[anIndex]

...

HTML syntax:

Argument list:

anElementID

The ID value of the element required

anIndex

A reference to an element in a collection

aName

An associative array reference

Object properties:

disabled, label

Event handlers:

onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

disabled

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

-

label

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

-

1662

O – OptGroupElement.disabled (Property)

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onDblClick

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onHelp

-

5.0 +

-

5.0 +

-

-

-

Warning

onKeyDown

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onKeyPress

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onKeyUp

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onMouseMove

1.5 +

5.0 +

6.0 +

5.0 +

-

-

4.0 +

Warning

onMouseOut

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.5 +

5.0 +

6.0 +

5.0 +

3.0 +

-

4.0 +

Warning

Inheritance chain: Element object, Node object

OptGroupElement.disabled (Property) A switch for activating or deactivating a grouped option set. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Property/method value type:

Boolean primitive

JavaScript syntax:

-

.myOptGroupElement.disabled

OptGroupElement.label (Property) A label that is applied to a group of options. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myOptGroupElement.label

1663

JavaScript Programmer's Reference

Option object (Object/HTML) One of a set of objects belonging to a select object in a form. Availability:

DOM level –1 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0 Opera browser –3.0

Inherits from:

Element object

JavaScript syntax:

IE

IE

myOption = myDocument.all.anElementID.elements [anIndex].options[anIndex] myOption = myDocument.all.anElementID.options[anIndex] myOption = myDocument.all.tags("OPTION")[anIndex]

IE

myOption = myDocument.all[aName]

-

myOption = myDocument.forms[aFormIndex] .aSelectorName.options[anIndex] myOption = myDocument.forms[aFormIndex].elements [anIndex].options[anIndex] myOption = myDocument.getElementById(anElementID)

IE IE

-

Argument list:

myOption = myDocument.getElementsByName(aName) [anIndex] myOption = myForm.aSelectorName.options[anIndex]

-

myOption = myForm.elements[anItemIndex].options [anIndex] myOption = myOptionsArray[anIndex]

-

myOption = mySelector.options[anIndex]

-

myOption = myDocument.getElementsByTagName("OPTION")[anIndex]

-

HTML syntax:

myOption = myDocument.aFormName.aSelectorName .options[anIndex] myOption = myDocument.aFormName.elements [anItemIndex].options[anIndex] myOption = myDocument.all.anElementID

... anIndex

A valid reference to an item in the collection

anItemIndex

A valid reference to an item in the collection

aName

The name attribute of an element

aFormIndex

A reference to a particular form in the forms collection

anElementID Object properties:

1664

The ID attribute of an element defaultSelected, form, index, label, prototype, selected, text, value

O – Option object (Object/HTML)

Event handlers:

onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp

In Netscape, this sub-class of the Input object supports a couple of properties that may not be available on other platforms. The DOM level 1 specification calls this object type an OptionElement object.

Warnings: ❑

In Netscape, this object is easy to confuse with the Select object to which the options belong. Be careful to maintain the correct structural relationship between Select popup menus and their option sets.



Netscape 6.0 PR3 exhibited some instabilities in the support of this object; however, it is not certain whether the bug is still outstanding on the final release as well. The problem seemed related to the creation of new Option objects by means of the constructor. This is not something that everyone is going to be doing on all their pages so its not likely to be a show stopper unless its just that one thing you need to use. See also:

Form.elements[], Input object, OptionsArray object, response.getOptionValue(), response.getOptionValueCount(), Select object

Property

JavaScript

JScript

N

IE

Opera

NES DOM HTML

Notes

default Selected form

1.1 +

1.0 +

3.0 +

3.02 +

3.0 +

2.0 +

1+

-

-

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

1+

-

Warning

index

1.0 +

1.0 +

2.0 +

3.02 +

-

-

-

-

ReadOnly

label

1.5 +

-

6.0 +

-

-

-

1+

-

-

prototype

1.0 +

1.0 +

2.0 +

3.02 +

-

2.0 +

-

-

Warning

selected

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

1+

-

-

text

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

2.0 +

1+

-

ReadOnly

value

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

2.0 +

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

NES DOM HTML

Notes

onClick

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

-

4.0 +

Warning

onDblClick

4.0 +

4.0 +

3.0 +

-

-

4.0 +

Warning

1.2 +

3.0 +

onHelp

-

3.0 +

-

4.0 +

-

-

-

-

Warning

onKeyDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

-

4.0 +

Warning

onKeyPress

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

-

4.0 +

Warning

onKeyUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

-

4.0 +

Warning

onMouseDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

-

4.0 +

Warning

Table continued on following page

1665

JavaScript Programmer's Reference

Event name

JavaScript

JScript

N

IE

Opera

NES DOM HTML

Notes

onMouseMove onMouseOut onMouseOver onMouseUp

1.2 + 1.1 + 1.0 + 1.2 +

3.0 + 3.0 + 1.0 + 3.0 +

4.0 + 3.0 + 2.0 + 4.0 +

4.0 + 4.0 + 3.0 + 4.0 +

3.0 + 3.0 + 3.0 +

-

Warning Warning Warning Warning

-

4.0 + 4.0 + 4.0 + 4.0 +

Inheritance chain: Element object, Node object

Option() (Constructor) An Option object constructor. Availability:

JavaScript –1.1 Netscape –3.0

JavaScript syntax:

N

new Option

N

new Option()

N

new Option(aValue)

aValue

An initial value for the new option object

Argument list:

You can dynamically create new option objects and add them to the options array belonging to a Select object in a form. See also:

Constructor function, constructor property, Garbage collection, Memory leak, Reference counting, Select.options[]

Option.defaultSelected (Property) The selected state of this item when the form was created. Availability:

DOM level –1 JavaScript –1.1 JScript –1.0 Internet Explorer –3.02 Netscape –3.0 Netscape Enterprise Server version –2.0 Opera browser –3.0

Property/method value type:

Boolean primitive

JavaScript syntax:

-

myOption.defaultSelected

This is a Boolean value that indicates whether the tag in the HTML document source has the SELECTED HTML tag attribute present or not. Only one of the tags in a block should have the SELECTED attribute, unless multiple sections are allowed. You can refer to this value in the form checking script to see if the value of the select block has been changed since the page was loaded.

1666

O – Option.index (Property)

Option.index (Property) The index position within the select object set. Availability:

JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myOption.index

When you define tags within a block, they instantiate objects to represent each option. These are then made available as members of a collection belonging to the Select object and accessible via its options[] property. This property indicates the position of this Option object within that collection. The first Option object in the collection is located at index position zero. Note that modifying the set of objects in this collection can cause the index numbers of an option to change. See also:

Select.options[]

Property attributes: ReadOnly.

Option.label (Property) The text string that the user sees in the popup menu. This is another name for the Option.text property. Availability:

DOM level –1 JavaScript –1.5 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

N

myOption.label

Refer to: Option.text

1667

JavaScript Programmer's Reference

Option.prototype (Property) The prototype for the Option object that can be used to extend the interface for all Option objects. Availability:

JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0

Property/method value type:

Option object

JavaScript syntax:

-

Option.prototype

-

myOption.constructor.prototype

Warnings: ❑

Of all the objects supported by MSIE, this is the only one to provide an enumerable property that points at the prototype for the object. This is likely to be a bug in the enumeration flag settings for the Option object type. See also:

prototype property

Option.selected (Property) The selected state of this option item. Availability:

DOM level –1 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0 Opera browser –3.0

Property/method value type:

Boolean primitive

JavaScript syntax:

-

myOption.selected

This is the current selected state of the option item. If the user has not interacted with the parent Select object, this value will be the same as its initial defaultSelected value. If the user has chosen an alternative item from the collection, then this property will be set accordingly.

1668

O – Option.text (Property)

Option.text (Property) The text string that the user sees in the popup menu. Availability:

DOM level –1 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0 Opera browser –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myOption.text

Option items have a textual value enclosed between the opening and closing tags. This is a means of accessing that text without needing to resort to complex innerText or innerHTML tricks.

Property attributes: ReadOnly.

Option.value (Property) The text value that is returned to the server if this item is selected. Availability:

DOM level –1 JavaScript –1.2 JScript –3.0 Internet Explorer –4.0 Netscape –4.0 Netscape Enterprise Server version –2.0 Opera browser –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myOption.value

The text that the user sees is not necessarily the same as that sent back when the form is submitted. Some degree of normalization is available so that the user may see a text string but a lookup mechanism can replace that with a numeric value thereby saving some work in the server. See also:

Input.value

1669

JavaScript Programmer's Reference

OptionElement object (Object/DOM) One of a set of objects belonging to a select object in a form. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

JavaScript syntax:

-

myOptionElement = new OptionElement()

Refer to: Option object

OptionsArray object (Object/browser) A collection object that belongs to a select popup. Availability:

JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0

JavaScript syntax:

-

Object properties:

length

Object methods:

add(), item(), remove(), select()

myOptionsArray = mySelector.options

Warnings: ❑

Netscape 6.0 implements this in a DOM-compliant manner. That means the object type is an HTMLCollection object. This is a generic object type and there are no special methods or properties added to it. The things you might have done with an OptionsArray object are not going to work.



MSIE appears to implement this as a NodeList although you cannot tell because it doesn't make a constructor or prototype available for you to inspect. Collection object, Option object, Select object, Select.options[]

See also:

Property

JavaScript

JScript

N

IE

Opera

HTML

Notes

length

1.0 +

1.0 +

2.0 +

3.02 +

-

-

ReadOnly

1670

O – OptionsArray.add() (Method)

Method

JavaScript

JScript

N

IE

Opera

HTML

Notes

add()

-

3.0 +

-

4.0 +

-

-

-

item()

-

3.0 +

-

4.0 +

-

-

-

remove()

-

3.0 +

-

4.0 +

-

-

-

select()

-

3.0 +

-

4.0 +

-

-

-

OptionsArray.add() (Method) Adds a new option item to a select popup object. Availability: JavaScript syntax: Argument list:

JScript –3.0 Internet Explorer –4.0 myOptionsArray.add(anObject) IE IE anObject

myOptionsArray.add(anObject, anIndex)

anIndex

The index position at which it should be added

An object to be added to the collection

You can use this method call to add a new item to a list of options belonging to a Select object. This would be manifested to the user as a new item being visible when the select menu is popped onto the display.

OptionsArray.item() (Method) Access to a particular item in the options collection of a select popup object. Availability:

JScript –3.0 Internet Explorer –4.0

Property/method value type:

Option object

JavaScript syntax:

IE

myOptionsArray.item(anIndex)

IE

myOptionsArray.item(aSelector)

IE

myOptionsArray.item(aSelector, anIndex)

anIndex

A zero based index into the collection

aSelector

A textual value that selects all matching objects

Argument list:

Because the OptionsArray is a sub-class of the generic Collection object, all the normal things you can do with a collection are possible with an OptionsArray belonging to a Select object. See also:

Collection.Item()

1671

JavaScript Programmer's Reference

OptionsArray.length (Property) The number of options in a select popup. Availability:

JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myOptionsArray.length

Property attributes: ReadOnly.

Refer to: Collection.length

OptionsArray.remove() (Method) Removes an option from the collection belonging to a select popup object. Availability:

JScript –3.0 Internet Explorer –4.0

JavaScript syntax:

IE

myOptionsArray.remove(anIndex)

Argument list:

anIndex

A zero-based index into the collection

This should affect the display causing the popup at least to be refreshed. Manipulating the popup contents in this way may be useful and is particularly appropriate if you have two popups, one of which is a secondary selector whose available choices depend on the settings of the first.

OptionsArray.select() (Method) Select an item in an options array belonging to a select popup object. Availability:

JScript –3.0 Internet Explorer –4.0

JavaScript syntax:

IE

myOptionsArray.select()

Behaves as if the user had selected an item. This should highlight the item in the popup's usual user interface feedback manner and should set the appropriate values in the properties of the previously selected and freshly selected Option objects. See also:

1672

Input.select()

O – outerHeight (Property)

outerHeight (Property) An alias for the window.outerHeight property. Availability:

JavaScript –1.2 Netscape –4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myWindow.outerHeight outerHeight

outerWidth

outerHeight

Property attributes: ReadOnly.

Refer to: Window.outerHeight

outerWidth (Property) An alias for the window.outerWidth property. Availability:

JavaScript –1.2 Netscape –4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myWindow.outerWidth

-

outerWidth

1673

JavaScript Programmer's Reference

outerWidth

outerHeight

Property attributes: ReadOnly.

Refer to: Window.outerWidth

Overview (Background) JavaScript language and functionality overview. Availability:

ECMAScript edition –2

JavaScript originally started as a Netscape extension to provide some script-driven dynamic effects within the web page. At this time, Netscape had by far the greater penetration and was much more popular than the MSIE browser. MSIE rapidly caught up with the scripting functionality and extended it in different directions. In the typically competitive style of the Microsoft company, JScript rapidly became the equal of the Netscape 4.0 browser. However, now it's the turn of Netscape to up the stakes again with the introduction of Netscape 6.0, although Microsoft has a new version of MSIE at the stage of beta testing. In the two years Netscape has taken in releasing new browser, JavaScript has become standardized through the ECMA organization and has been deployed in a variety of non-browser contexts. It is now part of the fundamental scripting interface in Windows where its duty with the VBScript interpreter lies in automating desktop operations. JavaScript is now available on Unix platforms as a shell scripting language and in web servers for server-side programming. More recently, it has been adopted and modified to become WMLScript which is used in WAPstandard mobile phone. Even more recently it is becoming popular in Digital TV set-top box systems as part of the rapid merger of broadcast TV and web content. This is likely to be where JavaScript becomes a fairly dominant tool for developing interactive TV content.

1674

O – Overview (Background)

The language continues to evolve and penetrate new markets and systems. The core language has been standardized and several bindings are also reasonably stable through the efforts of the W3C, but there is still much to be done to ensure the language operates consistently across browsers. Now that Netscape and MSIE are implementing the standards-based features in similar ways for the most part, the differences between the two browsers are being squeezed into more esoteric areas such as sidebars and visual transition filters. Events still have some way to go, and it will be a while before DOM-style control is completely supported. There are also several new DOM components in level 2 and extensions in level 3. See the web reference for the article by Brendan Eich on "The Birth of JavaScript". See also:

DOM, ECMA, ECMAScript, JavaScript language

Cross-references: ECMA 262 edition 2 – section 4 ECMA 262 edition 3 – section 4

Web-references: http://home.netscape.com/comprod/columns/techvision/innovators_be.html

1675

P object (Object/HTML) An object that encapsulates a paragraph delimited by a

tag. Availability:

DOM level –1 JavaScript –1.5 JScript –3.0 Internet Explorer –4.0 Netscape –6.0

Inherits from:

Element object

JavaScript syntax:

IE

myP = myDocument.all.anElementID

IE

myP = myDocument.all.tags("P")[anIndex]

IE

myP = myDocument.all[aName]

-

myP = myDocument.getElementByID(anElementID)

-

myP = myDocument.getElementsByName(aName)[anIndex]

-

myP = myDocument.getElementsByTagName("P")[anIndex]

HTML syntax: Argument list:

Object properties: Event handlers:

,

...

anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

align onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

The

tag is a block-level tag. That means that it forces a line break before and after itself. The DOM level 1 specification refers to this as a Paragraph object. See also:

Element object

Error! No text of specified style in document.

Property

JavaScript

JScript

N

IE

align

1.5 +

3.0 +

6.0 +

4.0 +

Opera -

NES

ECMA

DOM

CSS HTML

Notes

-

-

1+

-

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onDblClick

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onDragStart

-

3.0 +

-

4.0 +

-

-

-

-

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

onKeyDown

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onKeyPress

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onKeyUp

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseDown

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseMove

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOver

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseUp

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Node object

P.align (Property) The alignment of the paragraph object with respect to its parent object. Availability:

DOM level –1 JavaScript –1.5 JScript –3.0 Internet Explorer –4.0 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myP.align

The alignment of the P object with respect to its containing parent object is defined in this property. The expected and widely available set of alignment specifiers are available: ❑

absbottom



absmiddle

1677

Chapter number



baseline



bottom



center



left



middle



right



texttop



top

.pac (File extension) Proxy lookup conversion file. This is a script container for a small and compact JavaScript function that returns a computed value indicating whether to proxy-serve a URL or not. See also:

Proxies, proxy.pac

Cross-references: Wrox Instant JavaScript – page – 58

package (Reserved word) Reserved for future language enhancements. See also:

export, import, Reserved word

Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3

Packages (Property) An alias for the window.Packages property. Availability:

JavaScript –1.1 Netscape –3.0 Opera –3.0

Property/method value type:

JavaPackage object

JavaScript syntax:

N

myWindow.Packages

N

Packages

1678

Error! No text of specified style in document.

This property contains a read-only reference to a JavaPackage that sits at the top of the Java package hierarchy, the root node of the tree. A JavaPackage is a container for other JavaPackage objects and JavaClass objects. By default, the Netscape Navigator browser will have three packages belonging to this top-level node (java, sun, and Netscape), and these will contain other packages. There may be additional externally, supplied packages over and above these three default items. It is understandable that Microsoft does not go very far with support for Java other than being able to run a Java applet. There is no access to Java packages directly from script in the same way. You can run a Java Applet and interact with that, but its not quite the same thing. Perhaps because it is so platform-specific, not very many people have explored the use of packages very deeply, even on Netscape Navigator. That seems a shame because within a captive intranet situation, you might be able to accomplish some useful things by creating fragments of very powerful Java code and then calling them from JavaScript. There doesn't seem to be the lengthy start up time that's required to initiate an Applet either. root

netscape

java

lang

See also:

io

sun

applet

Window.Packages

Property attributes: ReadOnly.

Packages.java (Java package) A package containing a collection of generic Java classes maintained as a package. Availability:

JavaScript –1.1 Netscape –3.0 Opera –3.0

An example of a Package reference is the Java Date class stored in the java.util package.

1679

Chapter number

To access this from JavaScript you would use this kind of construction: myJavaClass = Packages.java.util.Date; That mode of access would yield a reference to the Class and would produce a JavaClass object in the JavaScript environment. To create an instance and yield an object of that class, use the class as a constructor. Like this: myJavaObject = new Packages.java.util.Date; That would create a JavaObject object in the JavaScript environment. If necessary, you may want to access a collection of Classes, which is called a Package. Here is how to create a JavaScript environment's JavaPackage object: myJavaPackage = Packages.java.util; See also:

JavaClass object, JavaObject object, JavaPackage object, Window.java

Packages.netscape (Java package) A package containing a collection of Netscape-defined Java classes maintained as a package. Availability:

JavaScript –1.1 Netscape –3.0 Opera –3.0

This is a code support for Java applets that use LiveConnect to access JavaScript from within the Java context. See also:

JavaClass object, JavaObject object, JavaPackage object, Window.netscape

Packages.netscape.javascript (Java package) A package containing support for Java code that needs to integrate with JavaScript via LiveConnect. Availability:

Refer to: Java calling JavaScript

1680

JavaScript –1.1 Netscape –3.0

Error! No text of specified style in document.

Packages.netscape.plugin (Java package) A package containing support for applets and plugins that integrate with JavaScript via LiveConnect. Availability:

JavaScript –1.1 Netscape –3.0

See also:

Plugin.description Plugin object

Packages.sun (Java package) A package containing a collection of Sun Microsystem- defined Java classes maintained as a package. This includes some Sun Java security support as well. Availability:

JavaScript –1.1 Netscape –3.0 Opera –3.0

See also:

JavaClass object, JavaObject object, JavaPackage object, Window.sun Java calling JavaScript

pageXOffset (Property) An alias for the window.pageXOffset property. Availability:

JavaScript –1.2 Netscape –4.0

Property/method value type:

Number primitive

JavaScript syntax:

N

myWindow.pageXOffset

N

pageXOffset

Offset X

Offset Y

1681

Chapter number

Property attributes: ReadOnly.

Refer to: Window.pageXOffset

pageYOffset (Property) An alias for the window pageYOffset property. Availability:

JavaScript –1.2 Netscape –4.0

Property/method value type:

Number primitive

JavaScript syntax:

N

myWindow.pageYOffset

N

pageYOffset

Property attributes: ReadOnly.

Refer to: Window.pageYOffset

ParamElement object (Object/HTML) An object that encapsulates one of the parameters passed to an OBJECT object from its tags. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Inherits from:

Element object

JavaScript syntax:

IE

myParam = myDocument.all.anElementID

IE

myParam = myDocument.all.tags("PARAMETER") [anIndex] myParam = myDocument.all.[aName]

IE HTML syntax:

1682

myParam = myDocument.getElementByID(anElementID) myParam = myDocument.getElementsByName(aName)[anIndex] myParam = myDocument.getElementsByTagName ("PARAMETER")[anIndex]

Error! No text of specified style in document.

Argument list:

anElementID

The ID value of the element required

anIndex

A reference to an element in a collection

aName

An associative array reference

Object properties:

name, type, value, valueType

Event handlers:

onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp

This is a new object introduced with the DOM specification. Its full name is HTMLParamElement. It can only exist as a child element within a block structured tag. Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

name type value valueType

1.5 + 1.5 + 1.5 + 1.5 +

5.0 + 5.0 + 5.0 + 5.0 +

6.0 + 6.0 + 6.0 + 6.0 +

5.0 + 5.0 + 5.0 + 5.0 +

-

1+ 1+ 1+ 1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick onDblClick onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp

1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 +

5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 +

6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 +

5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 +

-

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning

Inheritance chain: Element object, Node object

ParamElement.name (Property) The name of the parameter passed to the OBJECT object. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myParamElement.name

1683

Chapter number

ParamElement.type (Property) The type of parameter being passed to an OBJECT object when the valueType property is set to "ref". Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myParamElement.type

ParamElement.value (Property) The data value being passed to the OBJECT object in the parameter. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myParamElement.value

ParamElement.valueType (Property) The type of the value data that is being passed. Availability:

DOM level –1 JavaScript –1.5 JScript –5.0 Internet Explorer –5.0 Netscape –6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myParamElement.valueType

Parameter (Definition) The formal description of a function interface. The arguments that a function expects to be passed when it is called are described as a set of formal parameters when it is declared.

1684

Error! No text of specified style in document.

The parameters are called arguments from within the function when it is executed. Since JavaScript is weakly data-typed, you do not need to specify the data type of the parameters in the function declaration. Nor are the arguments tested for compliance with any data type when the function is invoked. Rather the values of any arguments are coerced or cast as they are used according to the context in which they are referred to. This makes it very important that you take care with the type and value of parameters you are passing to functions. In particular with numeric and string values. See also:

Argument, Argument list, Arguments object, Definition, Function, Function object, function( ... ) ..., Function.arguments[], Reserved word, Scope chain

parent (Property) An alias for the window.parent property. Availability:

JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Opera –3.0

Property/method value type:

Window object

JavaScript syntax:

-

myWindow.parent

-

parent

Property attributes: ReadOnly.

Refer to: Window.parent

Parentheses ( ) (Delimiter) A precedence of execution control mechanism. Availability:

ECMAScript edition –2 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0 Opera –3.0

Expression evaluation order is controlled by enclosing expressions in parentheses.

1685

Chapter number

See also:

Grouping operator ( )

Cross-references: ECMA 262 edition 2 – section – 11.1.4 ECMA 262 edition 3 – section – 11.1.6

parseFloat() (Function/global) Parse a string to extract a floating-point value. Availability:

ECMAScript edition –2 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0 Opera –3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

parseFloat(aNumericString)

Argument list:

aNumericString

A meaningful numeric value

The parseFloat() function returns a numeric value, unless the string cannot be resolved to a meaningful value in which case NaN is returned instead. It produces a number value dictated by interpreting the contents of the string as if it were a decimal literal value. During conversion parseFloat() ignores leading white space characters so you don't have to remove them from the string before conversion takes place. Note that parseFloat() will only process the leading portion of the string. As soon as it encounters an invalid floating-point numeric character it will assume the scanning is complete. It will then silently ignore any remaining characters in the input argument. See also:

Cast operator, Global object, parseInt(), String concatenate (+)

Property attributes: DontEnum.

Cross-references: ECMA 262 edition 2 – section – 15.1.2.3 ECMA 262 edition 3 – section – 15.1.2.3

1686

Error! No text of specified style in document.

parseInt() (Function/global) Parse a string to extract an integer value. Availability:

ECMAScript edition –2 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Netscape Enterprise Server version –2.0 Opera –3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

Argument list:

parseInt(aNumericString, aRadixValue)

aNumericString

A string that comprises a meaningful numeric value

aRadixValue

A numeric value indicating the radix for conversion

The parseInt() function produces an integer value dictated by interpreting the string argument according to the specified radix. It can happily cope with hexadecimal values specified with the leading 0x or 0X notation. During conversion parseInt() will remove any leading whitespace characters. You don't need to do that to the string before parsing it. Note also that parseInt() may only interpret the leading portion of a string. As soon as it encounters an invalid integer numeric character it will assume the scanning is complete. It will then silently ignore any remaining characters in the input argument. Typical radix values are: ❑

2 –Binary



8 –Octal



10 –Decimal



16 –Hexadecimal

The result of this function call is an integer value, unless the string cannot be resolved to a meaningful value in which case NaN is returned instead. See also:

Cast operator, Function property, Global object, parseFloat(), String concatenate (+)

Property attributes: DontEnum.

Cross-references: ECMA 262 edition 2 – section – 15.1.2.2 ECMA 262 edition 3 – section – 15.1.2.2

1687

Chapter number

Password object (Object/DOM) A text field in a form that echoes bullets instead of the typed character. Behaves as if it were a text cell but you cannot see what was typed. Availability:

DOM level –1 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Opera –3.0

Inherits from:

Input object

JavaScript syntax:

-

myPassword = myDocument.aFormName.anElementName

IE

myPassword = myDocument.aFormName.elements[anItemIndex] myPassword = myDocument.all.anElementID

IE

myPassword = myDocument.all.tags("INPUT")[anIndex]

IE

myPassword = myDocument.all[aName]

-

myPassword = myDocument.forms[aFormIndex].anElementName myPassword = myDocument.forms[aFormIndex].elements [anItemIndex] myPassword = myDocument.getElementByID(anElementID)

HTML syntax: Argument list:

myPassword = myDocument.getElementsByName(aName)[anIndex] myPassword = myDocument.getElementsByTagName ("INPUT")[anIndex]

anIndex

A valid reference to an item in the collection

aName

The name attribute of an element

anElementID

The ID attribute of an element

anItemIndex

A valid reference to an item in the collection

aFormIndex

A reference to a particular form in the forms collection

Object properties:

maxLength, readOnly, size, type, value

Object methods:

handleEvent(), select()

Event handlers:

onAfterUpdate, onBeforeUpdate, onBlur, onChange, onFilterChange, onFocus, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onResize, onRowEnter, onRowExit, onSelect, onSelectStart

Many properties, methods, and event handlers are inherited from the Input object class. Refer to topics grouped with the "Input" prefix for details of common functionality across all sub-classes of the Input object super-class.

1688

Error! No text of specified style in document.

Event-handling support via properties containing function objects was added to Password objects at version 1.1 of JavaScript. Some implementations will not allow JavaScript to read the password string that the user has entered. This is good. You might imagine otherwise on the grounds that you'd expect then that JavaScript then won't be able to validate the password. If you think about this for a minute you'll realize that View Source in a web browser exposes your entire security checking regime. Its actually quite sensible to disallow JavaScript from inspecting the password field. But then, all the user has to do is run different browser – one that does access the contents of the password field. Realistically the validation of the password can only be done back at the server anyway and other than some simple range checking in the client end access to password values from JavaScript is of doubtful use. See also:

Element object, Form.elements[], FormElement object, Input object, Input.accessKey, onBlur, onChange, onFocus, Password.handleEvent()

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

maxLength

-

3.0 +

-

4.0 +

-

-

-

-

readOnly

-

3.0 +

-

4.0 +

-

-

-

ReadOnly

size

-

3.0 +

-

4.0 +

-

-

-

Warning

type

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

1+

-

ReadOnly

value

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

1+

-

-

Method

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

handleEvent() select()

1.2 + 1.0 +

1.0 +

4.0 + 2.0 +

3.02 +

3.0 +

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onAfterUpdate onBeforeUpdate onBlur onChange onFilterChange onFocus onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver

1.1 + 1.0 + 1.0 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.1 + 1.0 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 1.0 +

3.0 + 2.0 + 2.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.0 + 2.0 +

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.0 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

Warning Warning Warning 4.0 + Warning 4.0 + Warning 4.0 + Warning 4.0 + Warning 4.0 + Warning 4.0 + Warning 4.0 + Warning Table continued on following page

1689

Chapter number

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onMouseUp onResize onRowEnter onRowExit onSelect onSelectStart

1.2 + 1.2 + 1.0 + -

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

4.0 + 4.0 + 2.0 + -

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

3.0 + 3.0 + -

-

4.0 + -

Warning Warning -

Inheritance chain: Element object, Input object, Node object

Cross-references: O'Reilly JavaScript Definitive Guide – page – 645

Password.handleEvent() (Method) Pass an event to the appropriate handler for this object. Availability:

JavaScript –1.2 Netscape –4.0

Property/method value type:

undefined

JavaScript syntax:

N

myPassword.handleEvent(anEvent)

Argument list:

anEvent

An event to be handled by this object

This applies to Netscape prior to version 6.0. From that release onwards, event management follows the guidelines in the DOM level 3 event specification. On receipt of a call to this method, the receiving object will look at its available set of event-handler functions and pass the event to an appropriately mapped handler function. It is essentially an event dispatcher that is granular down to the object level. The argument value is an Event object that contains information about the event. See also:

handleEvent(), Password object

Password.maxLength (Property) The maximum length allowed for a password entry field. Availability:

JScript –3.0 Internet Explorer –4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

1690

myPassword.maxLength

Error! No text of specified style in document.

This defines the maximum number of characters that can be entered into the password field. The browsers differ in how they handle this value. Some will warn the user with a beep or flash on the screen, others simply stop accepting keystrokes when this number of characters has been entered. Input.maxLength, TextCell.maxLength

See also:

Password.readOnly (Property) Set to true if the Password field cannot be changed. Availability:

JScript –3.0 Internet Explorer –4.0

Property/method value type:

Boolean value

JavaScript syntax:

IE

myPassword.readOnly

The password value is defined but cannot be changed by the user. The user should not be able to see the password on the screen; however, you might be able to view source to see the value in the HTML document source. Don't rely on this for hiding passwords in pages and assume that users will discretely ignore them. You might as well publish the password in the page heading. Input.readOnly, TEXTAREA.readOnly, TextCell.readOnly

See also:

Property attributes: ReadOnly.

Password.select() (Method) All text in the password text entry cell is selected and can be cut and pasted by the user. Availability:

DOM level –1 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Opera –3.0

JavaScript syntax:

-

myPassword.select()

If the browser supports a Selection object or TextRange objects, you may then be able to access the selected text using JavaScript. Of course in a form object, the text of the whole object can also be accessed but this may not be what was selected because the user may select all or part of a page and that selection may span several form elements or select only part of a form element. See also:

Input.select(), Selection object

1691

Chapter number

Password.size (Property) The width of the password text box measured in characters. Availability:

JScript –3.0 Internet Explorer –4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myPassword.size

This is an approximate measure at best. You cannot be sure how wide this box really needs to be when using a proportionally spaced font in it. The browser will size the box close to an optimal size to cope with the specified number of characters.

Warnings: ❑

It can be quite distracting if the box size is too small to accommodate the maxLength number of characters. This can leave the user having to do some cumbersome select actions with the mouse or use arrow keys to reveal the hidden parts of the textual content of the box. See also:

Input.size, TextCell.size

Password.type (Property) The type value for the object that describes the password text entry field in a form. Availability:

DOM level –1 JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myPassword.type

The type value for a password input text cell is always "password". This value is necessary to determine the type of form element because this object is really an instance of the Input class and not the Password class. There is actually no Password class. See also:

Property attributes: ReadOnly.

1692

Input.type

Error! No text of specified style in document.

Password.value (Property) The user-entered value for the password text cell. Availability:

DOM level –1 JavaScript –1.0 JScript –1.0 Internet Explorer –3.02 Netscape –2.0 Opera –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myPassword.value

This is the string value that is sent back to the web server when the form is submitted. It is difficult to store script-driven values in this property or to define default values in the HTML document source without revealing the password value to the user. More experienced users will be able to work out any default password values if you hide them. See also:

Input.value

Pattern matching (Definition) Part of the regular expression support in some implementations of JavaScript.

Refer to: RegExp pattern

PDF (Standard) A de facto standard for portable documents, which is owned by Adobe Inc. JavaScript is used inside Acrobat 4.0 as a forms-handling language. This provides a scripting environment in which you can manipulate the form data whose layout is defined by PostScript but whose content can then be 'activated' by JavaScript. There are a few minor limitations imposed due to the fact that Acrobat is not a web browser. There are also several additional objects provided to support the PDF forms environment. See also:

Host environment, Platform, Script execution

Web-references: http://www.pdfzone.com/pdfs/PDFSPEC13.PDF

1693

Chapter number

Perl Connect (Product) A mechanism for communicating between JavaScript and Perl scripts. This is a means of allowing JavaScript code to call a Perl interpreter from inside the JavaScript environment. It is functionally similar to using the eval() method but instead of evaluating JavaScript, some Perl source is passed instead.

Web-references: http://lxr.mozilla.org/mozilla/source/js/src/perlconnect/README.html

personalbar (Property) An alias for the window.personalbar property. Availability:

JavaScript –1.2 Netscape –4.0

Property/method value type:

Bar object

JavaScript syntax:

-

myWindow.personalbar

-

personalbar

See also:

Bar object

Property attributes: ReadOnly.

Refer to: Window.personalbar

Pitfalls (Advice) There are many pitfalls for the unwary in JavaScript. Although JavaScript is a very forgiving language, over the years it has become large and complex. There are certainly ways in which the unwary can be caught out. Even long experienced script developers are taken unawares from time to time.

1694

Error! No text of specified style in document.

We present warning sub-sections summarized under each topic. Several pitfalls are so large as to warrant a topic of their own. These are some examples: ❑

Accidentally closing tags within the script itself



Interpreting punctuation as tags



Quotes can be a problem



Hiding scripts from old browsers



Line breaks in document.write() methods



Browser detection for handling layers

The topic names (and hence their lexical order in this reference) are summarized in the See Also list: See also:

, Deprecated functionality, Escaped JavaScript quotes in HTML, Hiding scripts from old browsers, HTML entity escape, JavaScript entity, Newlines are not
tags, Off by one errors

Pixelate() (Filter/transition) A transition effect with the appearance of a coarse pixelated dissolve. Availability:

JScript –5.5 Internet Explorer –5.5

Refer to: filter – pixelate()

Pixelate() (Filter/visual) An effect that simulates the pixelation achieved when lowering the display resolution of an image. Availability:

JScript –5.5 Internet Explorer –5.5

Refer to: Filter – Pixelate()

Pkcs11 object (Object/Navigator) A hitherto undocumented object type supported by Netscape. Availability:

JavaScript –1.2 Netscape –4.04

JavaScript syntax:

N

myPkcs11 = myWindow.pkcs11

N

myPkcs11 = pkcs11

1695

Chapter number

The Pkcs11 object is part of the security model built into Netscape Navigator. It is otherwise known as Cryptoki and is provided by RSA Data Security, Inc. They implement a C language API that has now been mapped to Java as well. According to the Netscape web site, it is not a fully-fledged object-oriented API, but can be readily understood by programmers already familiar with Cryptoki. According to the release notes, Netscape 4.04 added support for the FORTEZZA PKCS#11 module for making use of the FORTEZZA Crypto Card and FORTEZZA cryptographic algorithms (KEA and Skipjack) when using SSL and S/MIME. Although a link was provided for more details, it appears that the support documents may have been moved or deleted. See also:

Cryptoki, Window.pkcs11

Property attributes: ReadOnly.

Web-references: http://developer.netscape.com/support/faqs/pkcs_11.html

PLAINTEXT object (Object/HTML) An object that encapsulates a deprecated tag. Availability:

JScript –3.0 Internet Explorer –4.0 Deprecated

Inherits from:

Element object

JavaScript syntax:

IE

myPLAINTEXT = myDocument.all.anElementID

IE

myPLAINTEXT = myDocument.all.tags("PLAINTEXT")[anIndex] myPLAINTEXT = myDocument.all[aName]

IE HTML syntax: Argument list:

myPLAINTEXT = myDocument.getElementByID(anElementID) myPLAINTEXT = myDocument.getElementsByName(aName)[anIndex] myPLAINTEXT = myDocument.getElementsByTagName ("PLAINTEXT")[anIndex]

anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID Event handlers:

1696

The ID value of an Element object onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

Error! No text of specified style in document.

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick onDblClick onDragStart onFilterChange onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart

-

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

-

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

Inheritance chain: Element object, Node object

Refer to: Element object

Platform (Definition) An environment is built to run on a platform that describes an OS and a hardware configuration. JavaScript is becoming available on a variety of platforms: ❑

Web browsers



TV set-top boxes



Mobile phones



Portable documents

Each of these uses JavaScript in a different way, although the core interpreted functionality is the same. Generally the differences will be in the area of the object model they support as part of the host environment. This is added to the core object model defined in the ECMA standard. See also:

CGI Driven JavaScript, Desktop JavaScript, Embedded JavaScript, File extensions, Host environment, iCab, Internet Explorer, Netscape , OpenTV, Opera, PDF, Script execution, Shell Scripting with JavaScript, Web browser, WebTV, WScript

1697

Chapter number

Cross-references: Wrox Instant JavaScript – page – 2 Wrox Instant JavaScript – page – 5

Plugin compatibility issues (Definition) Not all plugins behave the same. The area where you may experience the most difficulty with plugins is to do with video and media. There are now three major competing technologies and many other minority plugins that can play audio and video. If you just concentrate on the main players, you still have a lot of work to do. These are: ❑

Apple QuickTime



Progressive Networks Real Media



Windows Media Services

Functionally they are all very similar. Some of the protocols are shared between them and they all deliver multiple streams to a player plugin. Other plugins that you'll encounter will be: ❑

Macromedia Shockwave



Macromedia Flash



LiveAudio



Beatnik



PDF viewer



VRML viewer

Beyond that, some prefer an while others prefer tags. This is platform- and browser-dependant so on one browser a plugin may and on another, the same plugin will work best in an tag. Be aware that using the same plugin in the same browser and implementing it as an or an may mean that certain functionality is only available in one or the other. Given that you have got the plugin working with the correct tag and the features you need are available, the call-back message they use are not the same, nor are the method calls you can make on the plugin. Indeed, for some plugins, you may only be able to talk to them from JavaScript with the very latest version. Older versions simply ignore the JavaScript messages. Given that you now have your plugin running, in the right tags, and can talk to it, the functionality is different. Some plugins may allow the clip to be played backwards while others won't. Some may let you pause and play with different method calls, while at least one provides only a play_pause command. In that scenario, you can play or pause the clip but you won't actually know what state it is in.

1698

Error! No text of specified style in document.

Warnings: ❑

Netscape and MSIE encapsulate plugin/embedded objects in a different way. In MSIE they are objects of the EMBED class. In Netscape they are objects commonly referred to as belonging to the Plugin class.



There is additional confusion in that there is a plugins[] array that belongs to the document and another than belongs to the navigator object. They both contain collections of objects but of different types. This is further confused by the fact that the document.plugins[] array is another name for the document.embeds[] array.



Due to this confusing situation, the best recommendation is that we refer to document.embeds[] and navigator.plugins[] and quietly ignore the document.plugins[] array. Furthermore we shall refer to Plugin objects as being something the browser can use to play embedded content and, Embed objects, will be an instance of a plugin that is alive and running in a document. See also:

Compatibility, Plugin events

Plugin events (Definition) The events that are triggered by plugins are commonly referred to as callbacks. There are basically three kinds of plugins available with web browsers. These are: ❑

Microsoft tags enclosing ActiveX objects



Netscape tags enclosing browser plugins



Java tags enclosing Java applets

In Netscape Navigator, the LiveConnect mechanisms can run specific functions by name. This callback mechanism is available to and plugins, but it isn't clear to what extent this is supported by plugins so you may need to experiment with your browser to see what works and what doesn't. Use the and functionality as a guideline because the plugin handlers are all likely to share some code. Even so, it requires the Java VM (Virtual Machine) to be started for it to work. LiveConnect also requires that the tag contains the MAYSCRIPT attribute to give the applet permission to communicate with JavaScript. In MSIE, the callbacks are managed via ActiveX mechanisms. Again, an ActiveX object can call a named JavaScript function.

Warnings: ❑

The distinctions between these different plugin architectures become increasingly blurred and basically all of their functionality could probably have been provided with a single mechanism had the browser manufacturers worked together more co-operatively and been less concerned with carving out territory and gaining market share at each other's expense.



Interacting with plugins using JavaScript is possibly one of the least portable and most frustrating things to develop solutions for. The competing plugin suppliers have also utterly failed to develop common API calls for media players such that you need to treat each one as a special case even if you only want to play, pause, and stop video clips under JavaScript control.

1699

Chapter number



Neither of the mainstream browsers supports the other's chosen technology fully or reliably. It is not uncommon to find MSIE crashes on Windows with style plugins. Netscape Navigator does not support plugins at all well, and ActiveX code crashes a Macintosh horribly when either browser tries to run it. That's understandable since it's usually X86 machine code and right now Power PC processors don't like it. The latest MSIE version 5.0 for the Macintosh provides a switch to disable ActiveX plugins altogether. Even Microsoft Windows Media Player on Macintosh is supported by way of an tag. Real player is recommended to be used as an plugin on MSIE for Windows although it mostly works the same as an . There are some JavaScript API calls that are not available in both modes though.



This means for example to embed video into a page, even with the same kind of video, you basically have to implement four different containers to support MSIE and Netscape on Macintosh and Windows. Given that, there are now other browsers that can cope with plugins. That increases the number of varieties of HTML page content that needs to be created. Now that QuickTime, Windows Media Services and Real Media are all contending for market share, they all require different plugins and that multiplies your problem threefold. Now, it is likely that some of the platform/media combinations will be similar enough to share the same code. Even then, it still leaves you with something like six radically different ways that you will need to construct the plugin container if you want to do anything sophisticated and JavaScript driven. See also:

, Event, LiveConnect, Plugin compatibility issues, Plugin object

Cross-references: Wrox Instant JavaScript – page – 55

Plugin object (Object/browser) An object representing a plugin. Availability:

JavaScript syntax:

JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0 myPlugin = document.plugins[anIndex] N

myPlugin = navigator.plugins[anIndex]

-

myPlugin = myPluginArray[anIndex]

HTML syntax:

Argument list:

anIndex

Object properties:

description, filename, length, name

Object methods:

isActive(), refresh()

A reference to an element in a collection

Netscape and MSIE encapsulate plugin/embedded objects in a different way. In MSIE they are objects of the EMBED class. In Netscape Navigator they are objects commonly referred to as belonging to the Plugin class although they are really implemented as JavaObject objects. In MSIE, this is an ActiveX object.

1700

Error! No text of specified style in document.

There is additional confusion in that there is a plugins[] array that belongs to the document and another than belongs to the navigator object. They both contain collections of objects but of different types. This is further confused by the fact that the document.plugins[] array is another name for the document.embeds[] array. Because of this confusing situation the best recommendation is that we refer to document.embeds[] and navigator.plugins[] and quietly ignore the document.plugins[] array. Furthermore we shall refer to Plugin objects as being something the browser can use to play embedded content and an Embed object will be an instance of a plugin that is alive and running in a document.

Warnings: ❑

Do not confuse Plugin and Embed objects with one another. Plugin objects are owned by the navigator.plugins array. Embed objects are owned by the document.embeds array. See also:

, Collection object, Embed object, EmbedArray object, Glue code, Java, Navigator.plugins[], Plugin events, PluginArray object

Property

JavaScript

JScript

N

IE

Opera

HTML

Notes

description

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

ReadOnly

filename

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

ReadOnly

length

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

Warning, ReadOnly

name

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

ReadOnly

Method

JavaScript

JScript

N

IE

Opera

HTML

Notes

isActive()

1.3 +

-

4.7 +

-

-

-

-

refresh()

1.1 +

-

3.0 +

-

3.0 +

-

-

Plugin.description (Property) The descriptive text that a plugin yields when requested to do so. Availability:

JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myPlugin.description

The content of this string depends on what the plugin developer coded. It might be helpful for debugging and maybe you could present a list of installed plugins to the user. The standardization of the plugin descriptions is likely to be worse than that of the Navigator.userAgent string and therefore trying to formulate rules for parsing these descriptions is going to be difficult.

Property attributes: ReadOnly.

1701

Chapter number

Plugin.filename (Property) The filename that a plugin is stored in. Availability:

JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myPlugin.filename

This property may help in diagnosing plugins that are not working. If you can find out where in the file system it has installed, you may be able to go and replace it with an up-to-date copy if it is failing to work.

Property attributes: ReadOnly.

Plugin.isActive() (Method) A means of detecting whether an applet or plugin is still active. Availability:

JavaScript –1.3 Netscape –4.7

Property/method value type:

Boolean primitive

JavaScript syntax:

N

myPlugin.isActive()

Refer to: LiveConnect

Plugin.length (Property) The number of MIME types supported by the plugin. Availability:

JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

1702

myPlugin.length

Error! No text of specified style in document.

Warnings: ❑

Be careful not to confuse this property with the document.plugins.length and navigator.plugins.length properties.



The Plugin.length property is the number of MIME types that a plugin can respond to.



The document.plugins.length property gives a count of the number of plugins there are embedded into a document.



The navigator.plugins.length property is the number of plugin support modules that are installed and available to the browser. See also:

Collection.length, PluginArray.length

Property attributes: ReadOnly.

Plugin.name (Property) This corresponds to the NAME attribute of the tag that contains the plugin. Availability:

JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0

Property/method value type:

String primitive

JavaScript syntax:

-

HTML syntax:

Argument list:

aName

myPlugin.name

A name to identify the plugin object

Objects are identified either by the NAME="..." HTML tag attribute or by the ID="..." HTML tag attribute. Netscape shows a marginal preference for the name property while MSIE seems slightly better disposed towards the ID property. However in many cases, both browsers support either technique and in some cases will locate items named with either tag as if they existed in a single namespace. See also:

NAME="..."

Property attributes: ReadOnly.

1703

Chapter number

Plugin.refresh() (Method) A method to reload the plugin. Availability:

JavaScript –1.1 Netscape –3.0 Opera –3.0

JavaScript syntax:

N

myPlugin.refresh()

You need to refresh a plugin if you have installed it since the browser was started. This method is sometimes placed in pages that use plugins so that a refresh is forced every time the page is loaded. This is not strictly necessary but has been found to prevent some strange run-time errors in older versions of Netscape Navigator.

PluginArray object (Object/browser) A collection of plugin modules that the browser can use to playback embedded content. Availability:

JavaScript –1.1 JScript –3.0 Internet Explorer –4.0 Netscape –3.0 Opera –3.0

JavaScript syntax:

IE

myPluginArray = document.plugins

N

myPluginArray = navigator.plugins

Object properties:

length

Object methods:

item(), refresh()

Netscape and MSIE encapsulate plugin/embedded objects in a different way. In MSIE they are objects of the EMBED class. In Netscape Navigator they are objects commonly referred to as belonging to the Plugin class although they are really implemented as JavaObject objects. In MSIE, this is an ActiveX object. There is additional confusion in that there is a plugins[] array that belongs to the document and another than belongs to the navigator object. They both contain collections of objects but of different types. This is further confused by the fact that the document.plugins[] array is another name for the document.embeds[] array. Due to this confusing situation, the best recommendation is that we refer to document.embeds[] and navigator.plugins[] and quietly ignore the document.plugins[] array. Furthermore we shall refer to Plugin objects as being something the browser can use to play embedded content and an Embed object will be an instance of a plugin that is alive and running in a document.

1704

Error! No text of specified style in document.

Warnings: ❑

Beware of confusion between document.plugins and navigator.plugins. One relates to the plugins currently used in the document while the other lists the plugins currently available and supported by the browser.



In Netscape 4.7 for Macintosh, there is a strange enumeration problem. Immediately after starting the Netscape browser, when you enumerate the properties of the netscape.plugins PluginArray object, it appears to have no properties at all. If you explicitly ask for the length property, you will get a value. During investigation, it returned the value 8 but this will depend on the number of plugins you have installed.



Now, this suggests that you should be able to access the plugins individually by index number. As soon as you access one of the plugins by its numeric index, Netscape Navigator also adds an entry using the plugin name so you can access it associatively. However, you can also enumerate the item you just created until the browser clears the array (probably when the application exits). So, although you cannot enumerate the plugins from cold, you can enumerate the ones that you have accessed by index value.



Sending a refresh message to a plugin object also allows it to be enumerable. Based on this idea, a short fragment of code is given in the example that will force all the plugins to be added to the collection as associative items, which can then be enumerated.



MSIE allows the plugins to be enumerated and the length property is also enumerable. However, the plugins can only be accessed by their numeric index.



To make this properly portable, execute the bug fix code and access plugins by their numeric index and your scripts should then be reasonably portable.

Example code: // Execute this in Netscape Navigator to fix the // navigator.plugins enumeration bug for(ii=0; ii>>), Bitwise unsigned shift right and assign (>>>=)

Cross-references: ECMA 262 edition 2 – section – 11.7 ECMA 262 edition 3 – section – 11.7

short (Reserved word) Reserved for future language enhancements. The inclusion of this reserved keyword in the ECMAScript standard suggests that future versions of ECMAScript may be more strongly typed. This keyword also represents a Java data type and the short keyword allows for the potential extension of JavaScript interfaces to access Java applet parameters and return values. See also:

double, float, Integer, LiveConnect, long, Reserved word

Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3

1927

Chapter number

showHelp() (Method) Displays the help window. Availability: JavaScript syntax:

JScript – 3.0 Internet Explorer – 4.0 myWindow.showHelp() IE showHelp()

IE

Refer to: Window.showHelp()

showModalDialog() (Method) An alias for the window.showModalDialog() method. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

User defined

JavaScript syntax:

IE

Argument list:

IE aURL

myWindow.showModalDialog(aURL, someArguments) showModalDialog(aURL, someArguments) A URL to load into the modal dialog

someArguments

Arguments to pass to the modal dialog

Refer to: Window.showModalDialog()

showModelessDialog() (Method) An alias for the window.showModelessDialog() method. Availability: Property/method value type: JavaScript syntax:

Argument list:

JScript – 5.0 Internet Explorer – 5.0 User defined IE IE aURL

myWindow.showModelessDialog(aURL, someArguments) showModelessDialog(aURL, someArguments)

someArguments

1928

A URL to load into the modal dialog Arguments to pass to the modal dialog

Error! No text of specified style in document.

Refer to: Window.showModelessDialog()

.shtm (File extension) Server-side processed HTML file.

Refer to: File extensions

.shtml (File extension) Server-side processed HTML file.

Refer to: File extensions

Side effect (Definition) The changes to the execution environment due to some code being executed. When functions are executed, they may alter some item in memory or cause some change to occur aside from simply returning a value. For example, a function may create an object and add it to a persistent array and return some value such as the number of elements in that array. The calling expression was not aware that the array was extended and simply received a numeric value as a result of evaluating the function. The side effect was that the array became longer by one element. See also:

Expression, Script execution

Sidebar object (Object/Navigator) A new object introduced with Netscape 6.0 to manage the left side navigation bar. Availability:

JavaScript – 1.5 Netscape – 6.0

JavaScript syntax:

N

myWindow.sidebar

N

sidebar

This is a new object which needs to be explored as we get to know the netscape Navigator 6.0 browser. It encapsulates the behavior and appearance of the sidebar frame on the left of the browser window. See also:

Window.sidebar

1929

Chapter number

Signed scripts (Security related) A means of giving scripts a privilege to access secure content. Netscape Navigator allows scripts to have digital signatures attached to them. These signatures can control the level of privilege that a script is allowed to have in a web browser. This is ultimately under user control but if the user allows, the scripts can be secured at source. The signature combines the identity of the signatory and a checksum of the content. The content cannot be modified without invalidating the checksum and hence voiding the signature. It would be difficult to establish the exact security criteria beforehand, so Netscape Navigator forces scripts to request the privileges they need. Then, you can allow or deny the access which can be stored and mapped against the identity of the person signing the script. This means a security policy can gradually be established by training the browser to recognize and make decisions on access. Initially, no access is available but after some time, your browser preferences will contain a very sophisticated set of rules that govern the access to the secure values. To sign your scripts, you will need additional tools and utilities. These are available from Netscape and should form part of your publishing pipeline. An alternative is to serve your scripts separately from a secure server. Scripts served in this way will assumed to have been signed by the secure server itself. As a way round the inconvenience of signing scripts after every minor correction, you can sign the codebase of a script. This means you can establish a security setting for scripts from a specific web server. It is slightly less secure than signing a checksum but more convenient during development. It is recommended that proper signing be used; once the script changes are less frequent and the development process is complete, the scripts will be more stable and signing will be carried out less frequently. With some automation in the publishing work flow, you may be able to sign scripts as part of the releasing procedure that your developers employ. Your web page may contain more than one script. For signed script access control to work, all of the scripts on a page must be signed. If an unsigned script is present, it defeats the entire signing status of the whole page. Scripts can be signed by more than one person. Netscape Navigator will try and find the highest most complete coverage of the scripts in a page. Ideally it will find a particular signer who has signed all of the scripts. Other signers may have conferred a higher level of security but not on all of the scripts. The more complete coverage will prevail. Although these fairly strict same-signer policies apply to the scripts within a window, scripts in multiple windows may operate under a slightly relaxed policy. The "same signer" policy is a variation of the "same origin" policy. Different signers cause the browser to behave as if the pages were from different origins. Both scripts may have rights to request UniversalBrowserRead access which might work around the problem. Unsigned scripts have quite restricted access to window properties for windows that contain signed scripts. This means that untrusted and insecure scripts cannot access secure data by subverting an already trusted script.

1930

Error! No text of specified style in document.

Warnings: ❑

MSIE version 4 does not support the Netscape Navigator privilege model. Therefore scripts are always unprivileged. The MSIE security model is based on zones. This is a fairly coarse grained approach and simply allows scripts to be executed or not as a whole. The Netscape Navigator model allows access to be controlled object by object.



Being so closely related to the MSIE browser, the WebTV box also does not support signed scripts. See also:

AuthentiCode, Code signing, Data-tainting, export, import, JellyScript, Requesting privileges, Same origin

Web-references: http://developer.netscape.com/software/signedobj/ http://developer.netscape.com/library/documentation/signedobj/signtool/

Single line comment (Definition) A pair of slash characters (//) indicates single line comments. Single line comments are indicated by a pair of slash characters (//) and are completed by a line terminator. The pair of slash characters and everything following them to the end of the line is considered to be a comment. Comments are discarded during the interpretation phase of a line of script. A pair of slash characters would not behave as a comment delimiter if one of them were escaped with a backslash character or if they appeared inside a single or double quoted string literal. See also:

Comment, Comment (// and /* ... */), Line

Cross-references: ECMA 262 edition 2 – section – 7.3 ECMA 262 edition 3 – section – 7.4 Wrox Instant JavaScript – page – 17

Slide() (Filter/transition) A transition effect with the appearance of one image sliding over another. Availability:

JScript – 5.5 Internet Explorer – 5.5

Refer to: Filter – Slide()

1931

Chapter number

SMALL object (Object/HTML) An object that represents the font style controlled by the HTML tag. Availability:

JScript – 3.0 Internet Explorer – 4.0

Deprecated:

Yes

Inherits from:

Element object

JavaScript syntax:

IE

mySMALL = myDocument.all.anElementID

IE

mySMALL = myDocument.all.tags("SMALL")[anIndex]

IE

mySMALL = myDocument.all[aName]

-

mySMALL = myDocument.getElementById(anElementID)

-

mySMALL = myDocument.getElementsByName(aName)[anIndex] mySMALL = myDocument.getElementsByTagName("SMALL")[anIndex]

HTML syntax: Argument list:

... anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID Event handlers:

The ID value of an Element object onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

4.0 +

Warning

onDblClick

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onDragStart

-

3.0 +

-

4.0 +

-

-

-

-

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

onKeyDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyPress

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseMove

1.2 +

3.0 +

4.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

1932

Error! No text of specified style in document.

Inheritance chain: Element object, Node object

Refer to: Element object

snews: URL (Request method) A request from a web browser to a secure news server to send a document. Use the browser to download and browse some content from a secure news site. See also:

javascript: URL, Security policy, URL

Sort ordering (Definition) The mechanism by which items are arranged in sequence according to a locale. See also:

Localization

Refer to: Collation sequence

Source files (Definition) You can store JavaScript into external source files. You can link JavaScript source files at the client end, which causes the browser to fetch them and bind them into the page just like any other asset such as a style-sheet or image. See also:

.js

Cross-references: Wrox Instant JavaScript – page – 65 Wrox Professional JavaScript – page – 103

1933

Chapter number

Source text (Definition) Human readable script source text to be parsed and executed. Availability:

ECMAScript edition – 2

See also:

Comment, Escape sequence (\), Lexical convention, Script

Refer to: Script source text

Cross-references: ECMA 262 edition 2 – section 6 ECMA 262 edition 3 – section 6

SPAN object (Object/HTML) An object that encapsulates the contents of an inline tag. Availability:

JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object

JavaScript syntax:

IE

mySPAN = myDocument.all.anElementID

IE

mySPAN = myDocument.all.tags("SPAN")[anIndex]

IE

mySPAN = myDocument.all[aName]

-

mySPAN = myDocument.getElementById(anElementID)

-

mySPAN = myDocument.getElementsByName(aName)[anIndex] mySPAN = myDocument.getElementsByTagName("SPAN") [anIndex]

HTML syntax: Argument list:

Object properties: Event handlers:

1934

... anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

dataFld, dataFormatAs, dataSrc onBlur, onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

Error! No text of specified style in document.

tags and the objects that represent them are inline elements. Placing them into a document does not create a line break. Note that a positioned elements will appear as a member of the document.layers[] collection in Netscape 4. The example shows how properties of blocks can be moved from one to another. In this example, the background color of each block is moved along to the next in a cyclic manner as the mouse is clicked:

Example code:



ONE TWO THREE FOUR FIVE SIX





See also:

Element object

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

dataFld dataFormatAs dataSrc

-

3.0 + 3.0 + 3.0 +

-

4.0 + 4.0 + 4.0 +

-

-

-

-

1935

Chapter number

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onBlur onClick

-

3.0 + 3.0 +

-

4.0 + 4.0 +

-

-

4.0 +

Warning Warning

onDblClick onDragStart onFilterChange onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart

-

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

-

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

Inheritance chain: Element object, Node object

Special number values (Definition) Special properties of the Global and Number objects. Special number values are provided so that scripts can test for exceptional values yielded as a result of arithmetic expressions. You can check for infinity or non-number errors as a result of a divide by zero for example. Maximum and minimum values are also available to range check input data to make sure it can be used in arithmetic computations. You cannot assign constant values of Infinity or NaN because you cannot type in a constant value to denote them. However because they exist as properties of the Global object, you can refer to them by name.

Warnings: ❑

Be careful that you don't accidentally assign new values to the Infinity and NaN properties of the global object. Some implementations do not properly protect them against being written to and your script may assign new values to them. This can lead to very unpredictable behavior. See also:

Infinity, NaN, Number.MAX_VALUE, Number.MIN_VALUE, Number.NaN, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY

Cross-references: Wrox Instant JavaScript – page 14

1936

Error! No text of specified style in document.

Special type (Definition) Special data types are available to test variable content. There are two special data types available to test references to objects or the contents of variables. If a variable is currently of the type undefined, then it has not had any value stored in it. If it is a property, perhaps it has been deleted from the object. A variable reference would also yield the undefined value if it has not been declared. However, a reference to an undeclared variable causes a run-time error. Properties will yield the value null if they are supposed to contain an object and have been purposely nulled out. They will be undefined unless they have been set to null by an assignment. You can examine variables and object properties with the enquiry function to determine the type of the value stored there. The enquiry functions are: ❑

isNaN()



isFinite()

This operator behaves like an enquiry function: ❑

typeof

Testing for null and undefined or comparing them one with another can be problematical and is certainly non-trivial. In older versions of the browsers, you can simulate missing values. The null value can be simulated with this expression: (void 0) The undefined value can be simulated with this: (void null) Of course the simulations depend on the existence of some keywords that may or may not exist. See also:

isFinite(), isNaN(), null, typeof, undefined type

Spiral() (Filter/transition) Reveals the new image with a spiral effect. Availability:

JScript – 5.5 Internet Explorer – 5.5

Refer to: Filter – Spiral()

1937

Chapter number

SSJS (Definition) An abbreviation for Server-Side JavaScript.

Refer to: Server-side JavaScript

Stack manipulation (Useful tip) In Netscape 4, you can build stack managers. With the Array methods push(), pop(), unshift() and shift(), you can build various stacks and queues. A First In Last Out stack can be constructed with push() and pop(). This works from the end of the array. An alternative FILO stack can be constructed with unshift() and shift() but that will operate at the start of the array.

Array instance

Array instance

Array instance

Array instance

0

A

0

A

1

B

1

B

2

C

2

C

3

Array.push("X")

Array.pop()

3

Array.shift()

Array instance

Array instance

A

B

C

1938

Array.unshift("X")

A

B

C

X

Array instance

Array instance

B

C

D

X

A

B

C

Error! No text of specified style in document.

See also:

Array.pop(), Array.push(), Array.shift(), Array.unshift(), Queue manipulation

Standalone JavaScript (Definition) JavaScript that is executed in an application not associated with web pages at all. A stand-alone JavaScript implementation is when the interpreter is embedded into an application other than a web browser or web server. The application may utilize JavaScript as a mechanism for connecting its user interface to its internal functionality. This gives some benefits in being able to custom-tailor the way an application behaves and what is really delivered is a kit of components that are joined up with JavaScript glue. Stand-alone interpreters may have the scripts embedded inside the application or they may read them in from external sources. An example of a well known stand-alone interpreter is the Nombas ScriptEase range of JavaScript interpreters. The ScriptEase implementations have many additional objects to provide a very rich JavaScript programming environment indeed. See also:

Nombas ScriptEase

Cross-references: Wrox Instant JavaScript – page 68

Statement (Definition) A functional section of a program. Availability:

ECMAScript edition – 2

A statement is a discrete instruction in a script that causes something to happen. The statements in JavaScript can be classified into several categories. Here are the basic set of classifications: ❑

Block – Some code enclosed in braces.



Variable statement – A declaration of a local or global variable.



Empty statement – A semi-colon on its own.



Expression statement – An operator and its require operand(s).



If statement – Conditional execution of a block of code with an optional alternative block of code.



Iterative statement – A means of executing a block of code repetitively until a test condition is satisfied.



Switch selector – A means of executing one of a variety of possible code blocks selecting the best according to an input value.



Continue statement – A way of cancelling an iteration and commencing the next.

1939

Chapter number



Break statement – Means of breaking out of an iteration or a switch selector.



Return statement – A way to unconditionally leave a function and return to its caller, optionally handing back a value.



With statement – A means of adding an object to a scope chain.

Statements are executed in the order in which they appear in the script source text except when the flow of control is redirected by a conditional switching expression, function call, iterator or jump statement. See also:

break, Compound statement, continue, Empty statement (;), Expression statement, if( ... ) ..., if( ... ) ... else ..., Iteration statement, JavaScript language, Jump statement, Method, Punctuator, return, Script fragment, Semi-colon (;), var, Variable statement, with ...

Cross-references: ECMA 262 edition 2 – section 12 ECMA 262 edition 3 – section 12 Wrox Instant JavaScript – page 16

static (Reserved word) Reserved for future language enhancements.

Refer to: Reserved word

Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3

Static filters (Definition) These filters are used to define the appearance of an HTML Element object. They are all members of the visual filter family and are invoked through the stylesheet mechanisms or by the style object's filter property. Here is a list of the static filters: ❑

Alpha()



BasicImage()



Blur()



Chroma()



Compositor()



DropShadow()



Emboss()



Engrave()

1940

Error! No text of specified style in document.



FlipH()



FlipV()



Glow()



Grayscale()



Invert()



Light()



Mask()



MaskFilter()



Matrix()



MotionBlur()



Pixelate()



Shadow()



Wave()



XRay()

Some of these may not be available with all versions of the MSIE browser. Refer to the individual topics for availability. See also:

style.filter, Visual filters

Static method (Definition) Defines static methods using function properties you add to a function object. Static methods are also known as class methods. These are associated with a class rather than an instance of a class. The constructor function is analogous to the factory class for objects in truly object oriented systems. Static methods have no real use for the this keyword, as it is meant to refer to the receiving instance. These are called static methods because they are not associated with a local instance. See also:

Function object properties

Static variable (Useful tip) Defines static variables using properties you add to a function object. Static variables are also known as class variables. If we want to create some class variables, we need to add properties to the constructor function object. If we have made our own constructor function, we can add our own class variables to it. We can also add class variables to the built-in objects in some implementations. These are called static variables because they are not associated with a local instance. See also:

Function object properties

1941

Chapter number

status (Property) An alias for the window.status property. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myWindow.status

-

myWindow.status = aString

-

status

-

status = aString

Argument list:

aString

A string to display in the status bar

See also:

Window.defaultStatus, Window.status

Status code (Result value/NES) Many of the NES supported methods return a status code that is consistently defined across all objects and methods. The following methods will return a status code: ❑

database.execute()



database.beginTransaction()



database.commitTransaction()



database.rollbackTransaction()



cursor.insertRow()



cursor.updateRow()



cursor.deleteRow()

1942

Error! No text of specified style in document.

The status codes are summarized in the table: Code

Meaning

00

No error

01

Out of memory

02

Object was never initialized

03

Type conversion error

04

Database not registered

05

Error reported by database engine

06

Message from database engine

07

Error from database vendor's library

08

Lost connection

09

End of fetch

10

Invalid use of object

11

Column does not exist

12

Bounds error – invalid positioning within object

13

Unsupported feature

14

Null reference parameter

15

Database object not found

16

Required information missing

17

Object cannot support multiple readers

18

Object cannot support deletes

19

Object cannot support inserts

20

Object cannot support updates (1)

21

Object cannot support updates (2)

22

Object cannot support indices

23

Object cannot be dropped

24

Incorrect connection supplied

25

Object cannot support privileges

26

Object cannot support cursors

27

Unable to open

Status codes 5 and 7 are significant. It depends on the database being used as to which is important. Status code 5 is important for Oracle and ODBC. Status code 7 is important for Informix and Sybase. If these values are detected, then the major and minor error codes and messages can be inspected for further help in diagnosing the problems.

1943

Chapter number

See also:

Connection.majorErrorCode(), Connection.majorErrorMessage(), Connection.minorErrorCode(), Connection.minorErrorMessage(), Cursor.deleteRow(), Cursor.insertRow(), Cursor.updateRow(), database.beginTransaction(), database.commitTransaction(), database.execute(), database.majorErrorCode(), database.majorErrorMessage(), database.minorErrorCode(), database.minorErrorMessage(), database.rollbackTransaction(), Error handling

Status line (Definition) An area in the browser frame that status messages can be presented in. When browsers open a new window, they will have a status line at the bottom (unless you choose to deactivate the status line). This can have text messages presented to tell the user what is happening. One particularly popular usage is to present rollover text messages associated with links. There are two property values on each window that control the content of this status line. The defaultStatus property contains the text that is displayed when the mouse is not rolled over an active item. The status property is set to a specific value by an onMouseOver event handler and resets when the mouse leaves.

Warnings: ❑

The correct behavior is for the onMouseOver event handler to override the default behavior and replace the text in the status bar. Then, when the mouse rolls off of the active item, the defaultStatus value should be restored automatically.



This is not the case with all browsers. Macintosh and X-Windows versions of Netscape 3 (and possibly other browser versions) do not automatically restore the previous status line value. You will need to add a onMouseOut handler to explicitly reset the status line. See also:

onMouseOut, onMouseOver, Window.defaultStatus, Window.status

statusbar (Property) An alias for the window.statusbar property. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

Bar object

JavaScript syntax:

-

myWindow.statusbar

-

statusbar

1944

Error! No text of specified style in document.

See also:

Bar object, Window.statusbar

Property attributes: ReadOnly.

.stm (File extension) Server-side processed HTML file.

Refer to: File extensions

stop() (Method) An alias for the window.stop() method. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

undefined

JavaScript syntax:

N

myWindow.stop()

N

stop()

Refer to: Window.stop()

Storage duration (Definition) The time during which an entity is available for use. Objects and other entities may be created and destroyed at will while a script is being executed. Some are created automatically and some also get destroyed automatically. Some will be discarded when the script terminates either intentionally or accidentally due to an error of some kind. Objects may only persist while a function is being executed. They may vanish when the function returns to its caller.

1945

Chapter number

In a web browser, generally speaking, objects persist for the life of a page. They will be destroyed when the page is discarded or refreshed. Session storage can be accomplished effectively by maintaining a frame set where the outermost frame remains available throughout the session even though the pages it contains are replaced several times. In a server-side environment, objects and entities will likely only persist during the request-response loop. Items may persist longer if the server-side implementation is able to archive them or if it is able to maintain session state information between one request and another. In a TV set-top box environment, objects may persist for some time, perhaps for the duration of a broadcast program or for as long as the TV set-top box is tuned to a particular channel. Changing channels may purge out the object store. This particular kind of implementation is under constant and rapid development. One of the major areas of research is that of persistent and browsable cache systems where objects may repose and be recalled at will. In a system like that, objects may persist forever, or until the user chooses to dispose of them explicitly. See also:

Identifier, Request-response loop, Scope chain, Script execution, Script termination

Stproc object (Object/NES) An object that encapsulates a call to a stored procedure on a database from a Netscape Enterprise Server. Availability: JavaScript syntax:

Argument list:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0 myStproc = database.storedProc(aProcName, NES aProcParm); myStproc = myConnection.storedProc(aProcName, NES aProcParm) aProcName The name of a stored procedure to call aProcParm

A parameter value to pass to the stored procedure

Object properties:

prototype

Object methods:

close(), outParamCount(), outParameters(), resultSet(), returnValue()

This object provides a container to manage the call to the stored procedure and somewhere that the results can be made available for further processing by your scripts. You create Stproc objects by requesting them from the database or connection objects that are accessing the target database you are interested in.

Example code:

// An example derived from Wrox Professional JavaScript database.connect("ODBC", "myDatabase", "me", "myPassword", ""); myStproc = database.storedProc("myProcedure", 40);

1946

Error! No text of specified style in document.

See also:

Connection.storedProc(), Netscape Enterprise Server

Property

JavaScript

JScript

NES

Notes

prototype

1.2 +

-

3.0 +

-

Method

JavaScript

JScript

NES

Notes

close() outParamCount() outParameters() resultSet() returnValue()

1.2 + 1.2 + 1.2 + 1.2 + 1.2 +

-

3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

-

Stproc.close() (Method) Closes a stored procedure object when it is no longer required. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

JavaScript syntax:

NES

myStproc.close()

Although closures generally get dealt with automatically for you when a request handler exits, it is good style to call the closure methods yourself when you no longer need the database connection. See also:

ResultSet.close()

Stproc.outParamCount() (Method) Retrieves a count of the number of parameter values the stored procedure has returned. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

NES

myStproc.outParamCount()

Calling stored procedures is not like a normal database select. Because the results of a stored procedure are not strictly the results of a simple select but have been cached and processed by the procedure, the database will not generally return them as a record but as a collection of parameters. This method tells you how many there are so you can enumerate them in your script. See also:

ResultSet.columns()

1947

Chapter number

Stproc.outParameters() (Method) Retrieves an output parameter from the stored procedure. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

User defined

JavaScript syntax:

NES

myStproc.outParameters(anIndex)

Argument list:

anIndex

A parameter number

Given that we can obtain a count of the number of parameters returned by a stored procedure by calling the outParamCount() method, we can then enumerate them all and access the values that have been returned.

Stproc.prototype (Property) The prototype for the Stproc object that can be used to extend the interface for all Stproc objects. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

Stproc object

JavaScript syntax:

NES

Stproc.prototype

NES

myStproc.constructor.prototype

Refer to: prototype property

Stproc.resultSet() (Method) Retrieves a result set object from the stored procedure. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

ResultSet object

JavaScript syntax:

NES

myStproc.resultSet()

When you call a stored procedure in a RDMS, you don't always get back a sequence of records in the same layout and structure as when you just do a simple SQL select style query.

1948

Error! No text of specified style in document.

An SQL query would return a series of records separated by newline characters. A stored procedure might return a mixed collection of records of different types. A ResultSet object is created by asking the Stproc object for it when the stored procedure has been called and returned from the database. The traversing mechanisms provided with a result set allow you to move forwards through the data but you cannot move backwards. You also can only read values from a result set as opposed to a cursor which allows you to update and write new values back. See also:

ResultSet object

Stproc.returnValue() (Method) Retrieves the return value of the stored procedure. Availability:

JavaScript – 1.2 Netscape Enterprise Server version – 3.0

Property/method value type:

User defined

JavaScript syntax:

NES

myStproc.returnValue()

This is an indication of whether the stored procedure executed successfully or not. The values returned by this may depend on the kind of database adapter your middleware employed when connecting to the database.

Stretch() (Filter/transition) A variation on a wipe effect except that the new image appears to stretch over the old one. The old one is squashed until it disappears. Availability:

JScript – 5.5 Internet Explorer – 5.5

Refer to: Filter – Stretch()

1949

Chapter number

Strictly equal to (===) (Operator/identity) The two values must be exactly equal to one another in value and type. Availability:

JavaScript – 1.3 JScript – 1.0 Internet Explorer – 3.02 Netscape – 4.06

Property/method value type:

Boolean primitive

Refer to: Identically equal to (===)

STRIKE object (Object/HTML) An object that represents the font style controlled by the HTML tag. Availability:

JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object

JavaScript syntax:

IE

mySTRIKE = myDocument.all.anElementID

IE

mySTRIKE = myDocument.all.tags("STRIKE") [anIndex] mySTRIKE = myDocument.all[aName]

IE -

mySTRIKE = myDocument.getElementById (anElementID) mySTRIKE = myDocument.getElementsByName (aName)[anIndex] mySTRIKE = myDocument.getElementsByTagName ("STRIKE")[anIndex]

HTML syntax:

...

Deprecated:

Yes

Argument list:

anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID Event handlers:

1950

The ID value of an Element object onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

Error! No text of specified style in document.

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick onDblClick onDragStart onFilterChange onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onSelectStart

-

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

-

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

Inheritance chain: Element object, Node object

Refer to: Element object

String (Type) A native built-in type. Availability:

ECMAScript edition – 2

Property/method value type:

String primitive

Entities of type String are collections of zero or more Unicode characters. A string is arranged so that the characters in it can be accessed by their position. The leftmost character is considered to be at position 0 and the rightmost character is therefore at a position whose value is one less than the length of the string. This is convenient when processing strings in a for() loop since you can check the enumerator against the length and as long as it is less than the length and is a positive value, it is indexing within the string. Zero length strings are a special case. Strings can only be accessed read-only. You cannot change the contents of a string, you can only replace it with another.

1951

Chapter number

Warnings: ❑

You cannot reference strings with negative position values.

See also:

Cast operator, Data Type, Fundamental data type, String concatenate (+), toString(), Type, Type conversion, Unicode

Cross-references: ECMA 262 edition 2 – section 4.3.17 ECMA 262 edition 2 – section 6 ECMA 262 edition 2 – section 8.4 ECMA 262 edition 3 – section 4.3.17 ECMA 262 edition 3 – section 8.4 O'Reilly JavaScript Definitive Guide – page 38 O'Reilly JavaScript Definitive Guide – page 50

String (Primitive value) A built-in primitive value. Availability:

ECMAScript edition – 2

Property/method value type:

String primitive

A string value is a member of the type String and is a finite ordered sequence of zero or more Unicode characters. There is no way to represent a single character other than by means of a very short string. A string is not an array of characters as it would be in the C language. It is also not mutable as the other object data types that are passed by reference are. Strings are immutable and therefore to change one, you must manufacture a new string and discard the old one. This can lead to memory leaks. Strings can contain any Unicode character code point, however, many are not available on even the most international keyboard and must be escaped. You will need to check that the host environment can render the international symbols correctly if you use them. Strings can be delimited by either single or double quotes. This can be very useful for the occasions when a fragment of JavaScript is contained within some HTML. Refer to the String literal topic for a list of escape characters and more information on defining string values.

1952

Error! No text of specified style in document.

Warnings: ❑

Beware that the HTML escaping rules come into play when JavaScript is contained within HTML quote delimited name-value pairs in tags and you must be careful to escape any characters within scripts using the JavaScript escape mechanisms and not the HTML escape mechanisms. JavaScript inside

Character handling, Character testing, File.stringToByte(), String.prototype, Window.atob()

See also:

Cross-references: ECMA 262 edition 2 – section – 15.5.4.4 ECMA 262 edition 3 – section – 15.5.4.4

String.charCodeAt() (Method) The Unicode code point value of a character within the string. Availability:

ECMAScript edition – 2 JavaScript – 1.2 JScript – 5.5 Internet Explorer – 5.5 Netscape – 4.0 Netscape Enterprise Server version – 3.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myString.charCodeAt(aPosition)

Argument list:

aPosition

A valid character position within the string

This method returns the Unicode code point of the character at the indicated position. Note that the string index positions start at 0 and not 1. If there is no character at the indicated position the NaN value will be returned. This method may involve the receiver being converted to a string and so it can be applied generically to many kinds of objects. A

B

C

D

65

66

67

68

Character glyph Unicode value

charCodeAt(3)

1965

Chapter number

Warnings: ❑

If the result of calling this method creates a null string, then you may need to put in a special case handler. At the point where the null character appears, any string value will be truncated.



For example this:

"AAA" + String.fromCharCode(0) + "BBB"; will only display the "AAA" portion of the string. ❑

You can create other undesirable character values as well such as the delete character at the code point 127.



Characters at the code points 128 to 159 may display as question marks because they cannot be resolved to meaningful characters.



Character codes 208, 222, 240 and 254 render as a caret delimited character entity description word rather than as a single character glyph. This suggests that you should not rely on the output string having the same number of characters as the input numeric array. It also suggests there may be some problems converting number arrays to binary BLOb objects using this technique.



Note that the character code mapping does not necessarily correspond to the underlying code map of the platform the browser is running in.

Example code:

IndexCharCode


See also:

Arithmetic type, Cast operator, Character handling, Character testing, Character-case mapping, File.stringToByte(), Integer constant, JavaScript to Java values, String.fromCharCode(), String.prototype, Window.atob()

Cross-references: ECMA 262 edition 2 – section – 15.5.4.5 ECMA 262 edition 3 – section – 15.5.4.5

String.Class (Property/internal) Internal property that returns an object class. Availability:

1966

ECMAScript edition – 2

Error! No text of specified style in document.

This is an internal property that describes the class that a String object instance is a member of. The reserved words suggest that in the future this property may be externalized. See also:

Class, String object

Property attributes: DontEnum, Internal.

Cross-references: ECMA 262 edition 2 – section – 8.6.2 ECMA 262 edition 2 – section – 15.5.2.1 ECMA 262 edition 3 – section – 8.6.2

String.concat() (Method) A method for concatenating as opposed to the concatenate operator. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0 Netscape Enterprise Server version – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.concat(aString)

Argument list:

aString

A string to be concatenated to the receiving string

The concatenation operator (+) is the more common method of concatenating strings together. This method call: myString1.concat(myString2) is functionally equivalent to: myString1 + myString2 The second form is more intuitive in its meaning, and hence is recommended in favor of the concat() method.

1967

Chapter number

"A"

+

"B"

+

"C"

+

"D"

"ABCD"

Example code:



;

See also:

Array.concat()

Cross-references: ECMA 262 edition 3 – section – 15.5.4.6

String.constructor (Property) A reference to a constructor object. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0

Property/method value type:

String object

JavaScript syntax:

-

myString.constructor

The initial value of the String.prototype.constructor is the built-in String constructor. You can use this as one way of creating strings although it is more popular to use the new String() technique. This property is useful if you have an object that you want to clone but you don't know what sort of object it is. Simply access the constructor belonging to the object you have a reference to.

1968

Error! No text of specified style in document.

Netscape Navigator provides constructors for many objects, virtually all of them in fact, even when it is highly inappropriate to do so. MSIE is far more selective and there are some occasions when you might wish for a constructor that MSIE does not make available. See also:

String.fromCharCode(), String.prototype

Cross-references: ECMA 262 edition 2 – section – 15.5.4.1 ECMA 262 edition 3 – section – 15.5.2

String.fixed() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

myString.fixed()

Passing in the string "ABCD" will result in the following string: ABCD This is now deprecated in favor of the more sophisticated controls available with style sheets. See also:

style.fontFamily

String.fontcolor() (Method) Encapsulate the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

1969

Chapter number

JavaScript syntax: Argument list:

-

myString.fontcolor()

-

myString.fontcolor(aColor)

aColor

A color value to embed as an HTML tag attribute

Passing in the string "Colored text" with the parameter "RED" will result in the following string: ABCD This is now deprecated in favor of the more sophisticated controls available with style sheets. See also:

FONT.color, style.color

String.fontsize() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

myString.fontsize()

-

myString.fontsize(aSize)

aSize

A value to embed as an HTML tag attribute

Argument list:

Passing in the string "Small text" with the parameter "SMALL" will result in the following string: ABCD This is now deprecated in favor of the more sophisticated controls available with style sheets. See also:

FONT.size, style.fontSize

String.fromCharCode() (Method/static) A class-based factory method for converting numeric character codes to String objects. Availability:

1970

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0 Netscape Enterprise Server version – 3.0 Opera – 3.0

Error! No text of specified style in document.

Property/method value type:

String primitive

JavaScript syntax:

-

String.fromCharCode(aChar0, aChar1, aChar2, ...)

Argument list:

aCharN

a character code value

Constructs a new string from a sequence of Unicode character code point values each passed as a separate argument. This is a static method. So called because it belongs to the String() constructor and not any of the string objects. This means it is analogous to a class method in other object oriented environments.

Example code:





See also:

Arithmetic type, Cast operator, Character handling, Character testing, Character-case mapping, File.byteToString(), Java to JavaScript values, Keyboard events, onKeyDown, String.charCodeAt(), String.constructor, ToUint16, Window.atob(), Window.btoa()

Cross-references: ECMA 262 edition 2 – section 15.5.3.2 ECMA 262 edition 3 – section 15.5.3.2

String.indexOf() (Method) The location of a sub-string within a string. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myString.indexOf(aSearchString) myString.indexOf(aSearchString, aPosition)

1971

Chapter number

Argument list:

aPosition

An optional valid character position within the string to indicate the search start

aSearchString

A string to search for within the String object

Returns a value indicating the location of the search string within the receiving String object. If the search string is not found, the value -1 is returned. You can indicate a starting position within the target string and if that argument is missing, the whole string will be searched. The same happens if you put the value 0 into the second parameter.

Example code:





See also:

String.prototype

Cross-references: ECMA 262 edition 2 – section – 15.5.4.6 ECMA 262 edition 3 – section – 15.5.4.7

String.italics() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

1972

myString.italics()

Error! No text of specified style in document.

Passing in the string "Italicized text" will result in the following string: ABCD This is now deprecated in favor of the more sophisticated controls available with stylesheets. See also:

style.fontStyle

String.lastIndexOf() (Method) The location of the rightmost sub-string within a string. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myString.lastIndexOf(aSearchString)

myString.lastIndexOf(aSearchString, aPosition) aPosition An optional valid character position within the string to indicate the search start. Missing value or 0 indicates the entire string is to be searched aSearchString A string to search for within the string object -

Argument list:

Locates the rightmost occurrence of the search string within the receiving String object. If the search string cannot be found, then the value -1 is returned. If the starting position is not indicated, the entire string will be searched. The result of this method is the index of the rightmost occurrence of the sub-string or -1 if it is not found.

Example code:





See also:

String.prototype

1973

Chapter number

Cross-references: ECMA 262 edition 2 – section – 15.5.4.7 ECMA 262 edition 3 – section – 15.5.4.8

String.length (Property) The length of a String object's value. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myString.length

The length of the String object's value measured in characters. All String objects inherit properties and methods from the String prototype object. They will all return a value as a result of requesting the length property. The length value of a String object is immutable. This suggests that changing the value of a String object actually creates a new String object. This explains why continual string concatenations and modifications can sometimes cause a JavaScript execution to leak large amounts of memory as it runs. See also:

String object, String.prototype

Property attributes: ReadOnly, DontDelete, DontEnum.

Cross-references: ECMA 262 edition 2 – section 15.5.5 ECMA 262 edition 3 – section 15.5.5.1

String.link() (Method) Encapsulates the string within an tag context. Availability:

1974

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Error! No text of specified style in document.

Property/method value type:

String primitive

JavaScript syntax:

-

myString.link()

-

myString.link(aURL)

aURL

The URL to be embedded into an HREF HTML tag attribute

Argument list:

Passing in the string "A link" with the parameter "Some site" will result in the following string: ABCD This is useful for creating hyperlinks within the document. See also:

LINK object, String.anchor(), Url object

String.localeCompare() (Method) A locale sensitive string comparison. Availability:

ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0

Property/method value type:

Boolean primitive

JavaScript syntax:

-

myString.localeCompare(aString)

Argument list:

aString

A string to compare the value of this object against

The string passed as an argument is compared with the primitive value of the receiving String object. Using simple character comparison techniques they may not match and would fail an A == B test. The locale sensitive comparison takes special international characters and locale specific text issues into account and properly matches the strings.

Cross-references: ECMA 262 edition 3 – section – 15.5.4.9

String.match() (Method) Searches a string using a regular expression and returns the matches in an array. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

1975

Chapter number

Property/method value type:

Array object

JavaScript syntax:

-

myObject.match(aPattern)

Argument list:

aPattern

A regular expression pattern

This is one of the additions to the String object to support regular expressions. The matches are returned in an array with each match in a separate element. You can use this to strip numeric values out of a string containing words and numbers by looking for a pattern such as: /\d+/g This would yield all the numeric values from a string. The g attribute affects whether a single item matches or whether all of them match. When the g attribute is not used, the array object has an additional property named index, which contains the character location where the match occurred. It also has an additional property called input, which contains the original string that was searched for a match.

Warnings: ❑

This resets the lastIndex property of a RegExp object to 0.

Example code: myString = "JavaScript is good"; myLocation = myString.search(/GOOD/i); document.write(myLocation);

See also:

Array.index, Array.input, RegExp pattern, RegExp.exec(), RegExp.lastIndex, Regular expression, String.replace(), String.search(), String.split()

Cross-references: ECMA 262 edition 3 – section 15.5.4.10

String.prototype (Property) The prototype for the String object that can be used to extend the interface for all String objects. Availability:

ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Netscape Enterprise Server version – 3.0 Opera – 3.0

Property/method value type:

String object

1976

Error! No text of specified style in document.

JavaScript syntax:

-

String.prototype

-

myString.constructor.prototype

The prototype property refers to the built-in String prototype object. The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.

Example code:





See also:

prototype property, String object, String.charAt(), String.charCodeAt(), String.constructor, String.indexOf(), String.lastIndexOf(), String.length, String.split(), String.substring(), String.toLocaleLowerCase(), String.toLocaleUpperCase(), String.toLowerCase(), String.toString(), String.toUpperCase(), String.valueOf()

1977

Chapter number

Cross-references: ECMA 262 edition 2 – section 15.2.3.1 ECMA 262 edition 2 – section 15.5.3.1 ECMA 262 edition 2 – section 15.5.4 ECMA 262 edition 3 – section 15.5.3.1

String.replace() (Method) Searches a string using a regular expression and replace the matches. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

String primitive

JavaScript syntax:

-

myObject.replace(aPattern, aString)

aPattern

A regular expression pattern

aString

A replacement string

Argument list:

This is one of the additions to the String object to support regular expressions. The search pattern locates matches, which are then replaced by the string value in the second argument. The value is modified in place. The replacement text can make use of the numbered sub-expression references and can use them in the replaced string.

Warnings: ❑

This resets the lastIndex property of a RegExp object to 0.

Example code: // Simple replacement myString = "javascript, 'JAVASCRIPT', JavaScript"; myString.replace(/javascript/ig, "JavaScript"); document.write(myString); myString.replace(/^.*\'([^\']*)\'.*$/, "---''$1''---")

See also:

RegExp pattern, RegExp.exec(), RegExp.lastIndex, Regular expression, String.match(), String.search(), String.split()

Cross-references: ECMA 262 edition 3 – section – 15.5.4.11

1978

Error! No text of specified style in document.

String.search() (Method) Searches a string using a regular expression. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myObject.search( * aPattern )

Argument list:

aPattern

A regular expression pattern

This is one of the additions to the String object to support regular expressions. The character location where the match occurred is returned. If there is no match then the value -1 is returned instead. If you use the global attribute ('g'), then it will be ignored.

Warnings: ❑

This resets the lastIndex property of a RegExp object to 0.



Don't mix this search() method up with the search property that belongs to the Location object as they are totally different things. The temptation might be to refer to the position that the string search yielded as a location. This could be very confusing for someone working on your scripts later on.

Example code: myString = "JavaScript is good"; myResult = myString.search(/GOOD/i); document.write(myResult);

See also:

RegExp pattern, RegExp.exec(), RegExp.lastIndex, Regular expression, String.match(), String.replace(), String.split()

Cross-references: ECMA 262 edition 3 – section 15.5.4.12

1979

Chapter number

String.slice() (Method) Returns a sub-string sliced out of the original. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0 Netscape Enterprise Server version – 2.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.slice(startPos)

-

myString.slice(startPos, endPos)

endPos

The ending character position

startPos

The starting character position

Argument list:

The sub-string is identified using the parameters passed as arguments in the method call. The second argument is optional. If it is missing then it is assumed to mean the end of the string. End

Start A

B

C

D

E

F

G

H

I

J

K

M

N

O

Sub-string

Example code:





See also:

String.split(), String.substr(), String.substring()

Cross-references: ECMA 262 edition 3 – section – 15.5.4.13

1980

Error! No text of specified style in document.

String.small() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

myString.small()

Passing in the string "Small text" will result in the following string: Small text This is now somewhat deprecated in favor of the more sophisticated controls available with style sheets. See also:

style.fontSize

String.split() (Method) Splits a string and stores the components in an array. Availability:

ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

Array object

JavaScript syntax:

-

myString.split(aPattern)

-

myString.split(aSeparator)

Argument list:

myString.split(aSeparator, aCount) aPattern A regular expression to define the splitting sequence aSeparator A separator string to use for slicing the string aCount

An iterator count to limit the number of splits

1981

Chapter number

This method returns an array that contains the separated elements. The string is split using the separator string and each separate item is stored in an array element. The items in the array are ordered in the same sequence they were presented in the original string. This method is the complement of the join() method that is applied to arrays. The separator string is used to sub-divide the target string and is removed from the string component entities that result. The original string can be reconstructed by using the same separator in an Array.join() operation. If the separator string is omitted, then the string is simply stored in the first element of a new array without being split. This is not the same as specifying an empty string. That will cause the split to happen but because you have specified an empty string, and there is an empty string between each character, the string will turned into an array of individual characters. This is amazingly useful sometimes. In JavaScript version 1.2, this method is extended to allow the use of a regular expression as its argument. The match looks for the splitting delimiter. Using a constant character string inside the regular expression is functionally identical to using a string as the splitting value. Where this becomes powerful is where a character class or matching expression is used. The example shows how a string of letters separated by a variety of numeric digits can be split apart using a regular expression. This would be very difficult to do any other way and would require many more lines of code. "A@B@C@D"

String.split("@")

"A"

"B"

"C"

"D"

Array instance

1982

1

"A"

2

"B"

3

"C"

4

"D"

Error! No text of specified style in document.

Example code:





See also:

Array object, Array.join(), RegExp pattern, RegExp.exec(), Regular expression, String concatenate (+), String.match(), String.prototype, String.replace(), String.search(), String.slice(), String.substr(), String.substring()

Cross-references: ECMA 262 edition 2 – section – 15.5.4.8 ECMA 262 edition 3 – section – 15.5.4.14

String.strike() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

myString.strike()

Passing in the string "Struck out" will result in the following string: Struck out

1983

Chapter number

This is now deprecated in favor of the more sophisticated controls available with style sheets. See also:

style.textDecoration, style.textDecorationLineThrough

String.sub() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

myString.sub()

Passing in the string "Subscript text" will result in the following string: Subscript text This is now deprecated in favor of the more sophisticated controls available with style sheets. See also:

style.fontSize, style.fontStyle

String.substr() (Method) Returns a sub-string extracted from the original. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0 Netscape Enterprise Server version – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

Argument list:

myString.substr(aStartPosition, aLength) aStartPosition The index of the first character in the substring

myString.substr(aStartPosition)

aLength

1984

The length of the substring

Error! No text of specified style in document.

This is a variation of the String.substring() method. The difference is that the substring length is passed as the second argument rather than the substring ending character index.

Example code:





See also:

String.slice(), String.split(), String.substring()

Cross-references: ECMA 262 edition 3 – section – B.2.3

String.substring() (Method) Extracts a portion of a string. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.substring(aStartPosition, anEndPosition)

anEndPosition

A location within the string to end the substring extraction. If this is omitted then the end of the string is assumed to be the end position.

aStartPosition

A location within the string to begin the substring extraction.

Argument list:

If only one argument is provided, this method returns a sub-string starting at the indicated character position and proceeding to the and of the string. Where two arguments are provided the start and end points of the string are used to slice out a portion and return just that part. When just one argument is provided, the second is supplied internally and is taken to be end of the string.

1985

Chapter number

Where an argument is actually NaN rather than a meaningful value, then Zero is used instead. If any argument is greater than the length of the string, then the length of the string is used instead. Where the start point is larger than the end point, the two values are swapped over. This method is intentionally generic and can be applied to non-string objects. Where necessary, the receiving object may be converted to a string so that a sub-string can be extracted. The result returned by this method is the sequence of characters between the start and end positions of the source string. The value returned is a string primitive. See also:

String.prototype, String.slice(), String.split(), String.substr()

Cross-references: ECMA 262 edition 2 – section – 15.5.4.9 ECMA 262 edition 2 – section – 15.5.4.10 ECMA 262 edition 3 – section – 15.5.4.15

String.sup() (Method) Encapsulates the string within an tag context. Availability:

JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Deprecated:

Yes

Property/method value type:

String primitive

JavaScript syntax:

-

myString.sup()

Passing in the string "ABCD" will result in the following string: ABCD This is now deprecated in favor of the more sophisticated controls available with style sheets. See also:

1986

style.fontSize, style.fontStyle

Error! No text of specified style in document.

String.toLocaleLowerCase() (Method) Converts a string to all lower case using a locale sensitive character mapping. Availability:

ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.toLocaleLowerCase()

The result of this method will be a string primitive containing the value of the object with all characters converted to lower case. The original string is converted from arbitrary case to lower case on a character by character basis, taking account of the locale when testing characters. The characters in the output string will be the lower case equivalents of the characters in the input string according to the rules defined by the Unicode 2.0 standard, and the locale specific rules regarding special (accented) characters. See also:

Bit, Character handling, Character-case mapping, String.prototype, String.toLocaleUpperCase(), String.toLowerCase(), String.toUpperCase()

Cross-references: ECMA 262 edition 3 – section 15.5.4.17

String.toLocaleUpperCase() (Method) Converts a string to all upper case. Availability:

ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.5 Internet Explorer – 5.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.toLocaleUpperCase()

The result of this method is a string primitive containing the value of the object with all characters converted to upper case.

1987

Chapter number

The original string is converted from arbitrary case to upper case on a character by character basis, taking account of the locale when testing characters. The characters in the output string will be the upper case equivalents of the characters in the input string according to the rules defined by the Unicode 2.0 standard, and the locale specific rules regarding special (accented) characters. See also:

Bit, Character handling, Character-case mapping, String.prototype, String.toLocaleLowerCase(), String.toLowerCase(), String.toUpperCase()

Cross-references: ECMA 262 edition 3 – section 15.5.4.19

String.toLowerCase() (Method) Converts a string to all lower case. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.toLowerCase()

This method returns a string primitive containing the value of the object with all characters converted to lower case. The original string is converted from arbitrary case to lower case on a character by character basis. The characters in the output string will be the lower case equivalents of the characters in the input string according to the rules defined by the Unicode 2.0 standard. The Canonical Unicode 2.0 mapping will be used and therefore no special international character handling semantics take place. However non-ECMA compliant implementations may provide localization support not specified by ECMA 262. This method is intentionally generic and may be applied to a variety of object types other than strings. The effect of this method may depend on the locale settings in a fully localizable implementation. See also:

1988

Bit, Character handling, Character-case mapping, String.prototype, String.toLocaleLowerCase(), String.toLocaleUpperCase(), String.toUpperCase()

Error! No text of specified style in document.

Cross-references: ECMA 262 edition 2 – section 15.5.4.11 ECMA 262 edition 3 – section 15.5.4.16

String.toSource() (Method) Outputs a string formatted as a string literal contained in a string. Availability:

ECMAScript edition – 3 JavaScript – 1.3 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.06

Property/method value type:

String primitive

JavaScript syntax:

-

myBoolean.toString()

This is an alternative way to deliver a string primitive version of a String object's value. In this case, it is formatted as a string literal and can then be used in an eval() function to assign another string. If you run the example below, it should yield this as a result: (new String("ABCDEF")) The result of calling this method is a string version of the String object formatted as a string literal.

Example code: // Create a number and then examine its source myString = new String("ABCDEF"); document.write(myString.toSource());

String.toString() (Method) Returns a string primitive version of an object. Availability:

ECMAScript edition – 2 JavaScript – 1.3 JScript – 2.0 Internet Explorer – 4 Netscape – 4.06

Property/method value type:

String primitive

JavaScript syntax:

-

myString.toString()

Returns the string value as a primitive rather than an object.

1989

Chapter number

For a string object, the toString() method returns the same thing as the valueOf() method. See also:

String.prototype, String.valueOf(), toString()

Cross-references: ECMA 262 edition 2 – section 15.5.4.2 ECMA 262 edition 3 – section 15.5.4.2

String.toUpperCase() (Method) Converts a string to all upper case. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server version – 2.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myString.toUpperCase()

The result of this method is a string primitive containing the value of the object with all characters converted to upper case. The original string is converted from arbitrary case to upper case on a character by character basis. The characters in the output string will be the upper case equivalents of the characters in the input string according to the rules defined by the Unicode 2.0 standard. The Canonical Unicode 2.0 mapping will be used and therefore no special international character handling semantics take place. However non-ECMA compliant implementations may provided localization support not specified by ECMA 262. This method is intentionally generic and may be applied to a variety of object types other than strings. The effect of this method may depend on the locale settings in a fully localizable implementation. See also:

Bit, Character handling, Character-case mapping, String.prototype, String.toLocaleLowerCase(), String.toLocaleUpperCase(), String.toLowerCase()

Cross-references: ECMA 262 edition 2 – section 15.5.4.12 ECMA 262 edition 3 – section 15.5.4.18

1990

Error! No text of specified style in document.

String.valueOf() (Method) Returns the primitive value of the object. Availability:

ECMAScript edition – 2 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myString.valueOf()

The numeric equivalent of the string value is returned. In the case of a String object, the valueOf() method returns the same thing as the toString() method. This is proven by taking a string object and then using the == or === operators to compare the two values myString.toString() and myString.valueOf(). See also:

Cast operator, String.prototype, String.toString(), valueOf()

Cross-references: ECMA 262 edition 2 – section 15.5.4.3 ECMA 262 edition 3 – section 15.5.4.3

String operator (Definition) Operators that act on string values. There is only one string operator in the sense of a token that you can build a string expression out of. That is the concatenation operator. This may also be used to cast numeric values to string values by concatenating them to an empty string. See also:

Additive operator, String concatenate (+)

Strips() (Filter/transition) Reveals new image by sliding diagonal strips across the image. Availability:

JScript – 5.5 Internet Explorer – 5.5

1991

Chapter number

Refer to: Filter – Strips()

STRONG object (Object/HTML) An object representing the HTML content delimited by the tags. Availability:

JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object

JavaScript syntax:

IE

mySTRONG = myDocument.all.anElementID

IE

mySTRONG = myDocument.all.tags("STRONG")[anIndex]

IE

mySTRONG = myDocument.all[aName]

-

mySTRONG = myDocument.getElementById(anElementID)

-

mySTRONG = myDocument.getElementsByName(aName)[anIndex] mySTRONG = myDocument.getElementsByTagName("STRONG")[anIndex]

HTML syntax: Argument list:

... anElementID

The ID value of the element required

anIndex

A reference to an element in a collection

aName Event handlers:

An associative array reference onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

tags and the objects that represent them are inline elements. Placing them into a document does not create a line break. See also:

Element object

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

onDblClick

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

onDragStart

-

3.0 +

-

4.0 +

-

-

-

-

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

onKeyDown

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

onKeyPress

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

onKeyUp

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

onMouseDown

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

Table continued on following page

1992

Error! No text of specified style in document.

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onMouseMove

-

3.0 +

-

onMouseOut

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

4.0 +

-

-

4.0 +

Warning

onMouseOver

-

3.0 +

onMouseUp

-

3.0 +

-

4.0 +

-

-

4.0 +

Warning

-

4.0 +

-

-

4.0 +

Warning

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Node object

STYLE object (1) (Object/HTML) An object that encapsulates the anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

Object properties:

disabled, media, readyState, type

Event handlers:

onClick, onDblClick, onError, onHelp, onKeyDown, onKeyPress, onKeyUp, onLoad, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onReadyStateChange

The

Argument list:

...

A MIME type that signifies JavaScript source text.

someCode

Some script based style text

The same MIME type values that apply to the

2155

Chapter number

See also:

Element object, Form.elements[], FormElement object, Input object, Input.accessKey, onClick, SubmitButton.handleEvent()

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

type

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

1+

-

ReadOnly.

value

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

1+

-

Warning

Method

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

handleEvent()

1.2 +

-

4.0 +

-

-

-

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onAfterUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBeforeUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBlur

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

-

Warning

onClick

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

4.0 +

Warning

onDblClick

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onFocus

1.0 +

3.0 +

2.0 +

4.0 +

3.0 +

-

-

Warning

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

OnKeyDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyPress

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseMove

1.2 +

3.0 +

4.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onRowEnter

-

3.0 +

-

4.0 +

-

-

-

-

onRowExit

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Input object, Node object

2156

Error! No text of specified style in document.

SubmitButton.handleEvent() (Method) Passes an event to the appropriate handler for this object. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

undefined

JavaScript syntax:

N

mySubmitButton.handleEvent(anEvent)

Argument list:

anEvent

An event to be handled by this object

This applies to Netscape Navigator prior to version 6.0. From that release onwards, event management follows the guidelines in the DOM level 3 event specification. On receipt of a call to this method, the receiving object will look at its available set of event handler functions and pass the event to an appropriately mapped handler function. It is essentially an event dispatcher that is granular down to the object level. The argument value is an Event object that contains information about the event. See also:

SubmitButton object, Window.handleEvent()

SubmitButton.type (Property) The subclass type of this Input object. Availability:

DOM level – 1 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera browser – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

mySubmitButton.type

The type value for a SubmitButton is always "submit". This value is necessary to determine the type of form element, because this object is really an instance of the Input class. There is actually no SubmitButton class. See also:

Input.type

Property attributes: ReadOnly.

2157

Chapter number

SubmitButton.value (Property) The text string in the button. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera browser – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

mySubmitButton.value

Although this value may be sent back to the web server when the form is submitted, the main purpose of a Submit button is to trigger the form submission. This property provides a convenient means of labelling the button.

Warnings: ❑

This may be changed in some platforms but not others. See also:

Input.value, ResetButton.value

Subtract (-) (Operator/additive) Subtracts the right operand from the left operand. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera browser – 3.0

Property/method value type:

Number primitive

JavaScript syntax:

-

anOperand1 - anOperand2

Argument list:

anOperand1

A numeric value to be subtracted from

anOperand2

A numeric value to be subtracted

Subtraction is indicated when two operands are separated by a minus sign.

2158

Error! No text of specified style in document.

The value on the right is subtracted from the value on the left. The result is the difference between the two values. Subtraction behaves identically to addition, as if the formula: a - b had become: a + (-b) The associativity is left to right. Refer to the operator precedence topic for details of execution order. See also:

Add (+), Additive operator, Arithmetic operator, Assign value (=), Assignment expression, Associativity, Negation operator (-), Operator Precedence, Subtract then assign (-=)

Cross-references: ECMA 262 edition 2 – section 11.6.2 ECMA 262 edition 2 – section 11.6.3 ECMA 262 edition 3 – section 11.6.2

Subtract then assign (-=) (Operator/assignment) Subtracts the right value from the left, modifying the left-hand value. Availability:

ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0

Property/method value type:

Number primitive

JavaScript syntax:

-

anLValue -= anOperand

Argument list:

anLValue

An operand that can be assigned into

anOperand

A value to subtract

Subtracts the right operand from the left operand and assigns the result to the left operand. This is functionally equivalent to the expression: anOperand1 = anOperand1 - anOperand2; Although this is classified as an assignment operator it is really a compound of an assignment and an additive operator. The associativity is right to left. Refer to the operator precedence topic for details of execution order. The new value of anOperand1 is returned as a result of the expression.

2159

Chapter number

Warnings: ❑

The operand to the left of the operator must be an LValue. That is, it should be able to take an assignment and store the value. Add then assign (+=), Additive operator, Arithmetic operator, Assignment operator, Associativity, Operator Precedence, Subtract (-)

See also:

Cross-references: ECMA 262 edition 2 – section 11.13 ECMA 262 edition 3 – section 11.13

sun (Java package) A short cut reference to the Packages.sun object. Availability:

JavaScript – 1.1 Netscape – 3.0

Property/method value type:

JavaPackage sun

JavaScript syntax:

N

myWindow.Packages.sun

N

myWindow.sun

N

Packages.sun

N

sun

root

netscape

java

lang

See also:

Property attributes: ReadOnly.

2160

io

sun

applet

Window.java, Window.sun, Window.Packages

Error! No text of specified style in document.

SUP object (Object/HTML) An object that encapsulates the contents of a tag. Availability:

JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object

JavaScript syntax:

IE

mySUP = myDocument.all.anElementID

IE

mySUP = myDocument.all.tags("SUP")[anIndex]

IE

mySUP = myDocument.all[aName]

-

mySUP = myDocument.getElementById(anElementID)

-

mySUP = myDocument.getElementsByName(aName)[anIndex] mySUP = myDocument.getElementsByTagName("SUP") [anIndex]

HTML syntax: Argument list:

... anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID Event handlers:

The ID value of an Element object onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

OnClick

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

4.0 +

Warning

OnDblClick

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

OnDragStart

-

3.0 +

-

4.0 +

-

-

-

-

OnFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

OnHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

OnKeyDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyPress

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseMove

1.2 +

3.0 +

4.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.0 +

1.0 +

2.0 +

3.0 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Node object

2161

Chapter number

Refer to: Element object

super (Reserved word) Reserved for future language enhancements.

Refer to: Reserved word

Cross-references: ECMA 262 edition 2 – section 7.4.3 ECMA 262 edition 3 – section 7.5.3

Superclasses (Definition) Superclasses are the parent class of subclassed objects. Superclass mechanisms are used in true object oriented systems to provide a means of generalizing object descriptions and capturing common behaviors into a shared parent class. A superclass of an object may also have a superclass of its own. Eventually, by walking up the class hierarchy, you should arrive at the topmost class. That is probably the Object class but it can be implementation dependent. See also:

Anchor object, Subclasses

switch( ... ) ... case: ... default: ... (Selector) Selects one of a set of cases according to a switch value. Availability:

ECMAScript edition – 3 JavaScript – 1.2 JScript – 3.0 Internet Explorer – 4.0 Netscape – 4.0 Netscape Enterprise Server – 3.0

JavaScript syntax:

-

switch(aValue) { aCaseTree }

aCaseTree

A set of case statements to be selected.

aValue

An integer value used as a selector

Argument list:

The switch statement evaluates its expression and selects a labeled statement block for execution according to the value resulting from the expression. If there is no match, then a default case is used.

2162

Error! No text of specified style in document.

Each labeled case should be terminated by a break keyword to avoid the execution dropping down through into the handler for the next case in the script source. On the other hand, this may be what you intend and so omitting the break keyword allows several cases to be matched and handled with a common fragment of code. The use of switch is illustrated in the example. The value enclosed in parentheses is evaluated and its result is used as a selector. It looks for a matching case label and executes the code in that block. If it does not match, it uses the default block (if there is one). Unlike the ANSI C version of switch, the JavaScript one will match strings as well as integers. The break; statements prevent the code from dropping down into the next block. The following are all legal case labels: case 0: case 100*23: case "abc": case "aaa" + "bbb": case Number.NaN: The C language environment dictates that a switch statement must be capable of supporting at least 256 individual cases. The ECMAScript standard does not define a limit. You need to be careful when nesting switch statements. The case labels will be subordinate to the closest enclosing switch given the rules of precedence and block structuring of the code. Case labels must be unique within a single switch mechanism, but can duplicate case values in other switch structures within the same or an enclosing code block.

Warnings: ❑

Primitive values are allowed as selectors but objects, arrays and functions are not. You could wrap them with toString() or valueOf() functions though. However the results may be slightly unpredictable unless you thoroughly test the effects of those functions in all your target implementations.



The value document.forms.length is valid for use in a case label at JavaScript version 1.2 but may not be later. The values really do have to be constant, and it's possible that a later version of the interpreter may check the ReadOnly attribute of any property value that is used in this context.

Example code: // An example switch statement switch(myValue){ case 1: document.write("one"); break; case 'too': document.write("two"); break; default: document.write("unknown"); break; }

2163

Chapter number

See also:

break, Colon (:), else ..., Flow control, if( ... ) ..., if( ... ) ... else ..., Selection statement

Cross-references: ECMA 262 edition 2 – section 7.4.3 ECMA 262 edition 3 – section 7.5.2 ECMA 262 edition 3 – section 12.11

synchronized (Reserved word) Reserved for future language enhancements.

Refer to: Reserved word

Cross-references: ECMA 262 edition 2 – section 7.4.3 ECMA 262 edition 3 – section 7.5.3

SyntaxError object (Object/core) A native error object based on the Error object. Availability:

ECMAScript edition – 3 JavaScript – 1.5 Netscape – 6.0

Inherits from:

Error object

JavaScript syntax:

N

myError = new SyntaxError()

N

myError = new SyntaxError(aNumber)

N aNumber

myError = new SyntaxError(aNumber, aText)

aText

A text describing the error

Argument list:

An error number

This subclass of the Error object is used when an exception is caused by a script source text parsing error. See also:

2164

catch( ... ), Error object, EvalError object, RangeError object, ReferenceError object, throw, try ... catch ... finally, TypeError object, URIError object

Error! No text of specified style in document.

Inheritance chain: Error object

Cross-references: ECMA 262 edition 3 – section 15.1.4.13 ECMA 262 edition 3 – section 15.11.6.4

2165

TABLE object (Object/HTML) An object that represents a table within a document. Availability:

DOM level –1 JavaScript –1.5 JScript –3.0 Internet Explorer –4.0 Netscape –6.0

Inherits from:

Element object

JavaScript syntax:

IE

myTABLE = myDocument.all.anElementID

IE

myTABLE = myDocument.all.aTableID

IE

myTABLE = myDocument.all.tags("TABLE")[anIndex]

IE

myTABLE = myDocument.all[aName]

-

myTABLE = myDocument.getElementById(anElementID) myTABLE = myDocument.getElementsByName (aName)[anIndex] myTABLE = myDocument.getElementsByTagName ("TABLE")[anIndex]

HTML syntax: Argument list:

Object properties:

...
anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

align, background, bgColor, border, borderColor, borderColorDark, borderColorLight, caption, cellPadding, cellSpacing, cols, dataFld, dataPageSize, dataSrc, frame, height, rules, summary, tabIndex, tFoot, tHead, width

JavaScript Programmer's Reference

Object methods:

createCaption(), createTFoot(), createTHead(), deleteCaption(), deleteRow(), deleteTFoot(), deleteTHead(), insertRow(), nextPage(), previousPage(), refresh()

Event handlers:

onAfterUpdate, onBeforeUpdate, onBlur, onClick, onDblClick, onDragStart, onFilterChange, onFocus, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onResize, onRowEnter, onRowExit, onScroll, onSelectStart

Collections:

cells[], rows[], tBodies[]

Tables are a hierarchical means of describing a two dimensional array of cells containing HTML. Generally speaking the DOM compliant browsers provide a more sophisticated model of the table for access under control of a JavaScript program. There are a set of related object types that need to be understood to utilize tables most effectively: ❑

CAPTION



COL



COLGROUP



TBODY



TD



TFOOT



TH



THEAD



TR

The following style object properties should also be considered: ❑

style.captionSide



style.cellSpacing



style.columnSpan



style.emptyCells



style.rowSpan



style.tableLayout See also:

2168

CAPTION object, COL object, COLGROUP object, Element object, Element.offsetParent, style.captionSide, style.cellSpacing, style.columnSpan, style.emptyCells, style.rowSpan, style.tableLayout

T – TABLE object (Object/HTML)

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

align

6.0 +

4.0 +

-

1+

-

-

1.5 +

3.0 +

background

-

3.0 +

-

4.0 +

-

-

-

-

bgColor

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

border

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

borderColor

-

3.0 +

-

4.0 +

-

-

-

-

borderColorDark

-

3.0 +

-

4.0 +

-

-

-

-

borderColorLight

-

3.0 +

-

4.0 +

-

-

-

-

caption

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning, ReadOnly

cellPadding

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

cellSpacing

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

cols

-

3.0 +

-

4.0 +

-

-

-

-

dataFld

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

dataPageSize

-

3.0 +

-

4.0 +

-

-

-

-

dataSrc

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

frame

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

height

1.5 +

3.0 +

6.0 +

4.0 +

-

-

-

-

rules

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

summary

1.5 +

-

6.0 +

-

-

1+

-

-

tabIndex

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

tFoot

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

ReadOnly

tHead

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

ReadOnly

width

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

Method

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

createCaption()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

createTFoot()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

createTHead()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

deleteCaption()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

deleteRow()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

deleteTFoot()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

deleteTHead()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

insertRow()

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

nextPage()

-

3.0 +

-

4.0 +

-

-

-

-

previousPage()

-

3.0 +

-

4.0 +

-

-

-

-

refresh()

-

3.0 +

-

4.0 +

-

-

-

-

2169

JavaScript Programmer's Reference

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onAfterUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBeforeUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBlur

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

-

Warning

onClick

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onDblClick

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onDragStart

-

3.0 +

-

4.0 +

-

-

-

-

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onFocus

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

-

Warning

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

onKeyDown

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyPress

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onKeyUp

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseMove

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.5 +

3.0 +

6.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onResize

1.5 +

3.0 +

6.0 +

4.0 +

-

-

-

Warning

onRowEnter

-

3.0 +

-

4.0 +

-

-

-

-

onRowExit

-

3.0 +

-

4.0 +

-

-

-

-

onScroll

-

3.0 +

-

4.0 +

-

-

-

-

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Node object

TABLE.align (Property) A controlling property for the alignment of table cells within a table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

2170

myTABLE.align

T – TABLE.background (Property) The horizontal alignment of the TABLE object with respect to its containing parent object is defined in this property. The following set of alignment specifiers are available: ❑

center



left



right



char



justify See also:

TBODY.align, TD.align, TFOOT.align, TH.align, THEAD.align, TR.align

TABLE.background (Property) A URL of an image to be used as the background for a table. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTABLE.background

If a background image is available, then its URL is contained in this property. Changing the value in this property will replace the background with a new one. However, there may be a perceptible delay while the new image is fetched from the web server.

TABLE.bgColor (Property) The background color value for a table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTABLE.bgColor

The background can be colored independently of whether an image is loaded into the background of an object. In fact it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:

Color names, Color value

2171

JavaScript Programmer's Reference

TABLE.border (Property) The width of the border around cells in a table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTABLE.border

The thickness of the border around the table should be specified as an integer value describing a value measured in pixels. This describes the table border drawn with a 3D effect. If you add borders around any elements with the style properties, those describe a different border. See also:

TABLE.frame

TABLE.borderColor (Property) The color of the border around the cells in a table. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTABLE.borderColor

You can use this property to determine the color of a border surrounding a table. Note that there are additional properties to determine the highlights and lowlights of the table border coloring.

TABLE.borderColorDark (Property) The color value of the shadowed edge of the table border (assuming the table is lit from the top left). Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTABLE.borderColorDark

Table borders are presented as having an engraved appearance. This means you may need to control the highlights and lowlights. This property defines the color of the shadowed part of the table border.

2172

T – TABLE.borderColorLight (Property)

TABLE.borderColorLight (Property) The color value of the highlighted edge of the table border (assuming the table is lit from the top left). Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTABLE.borderColorLight

Table borders are presented as having an engraved appearance. This means you may need to control the highlights and lowlights. This property defines the color of the highlighted part of the table border.

TABLE.caption (Property) The caption text contained in a CAPTION object belonging to the TABLE object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

CAPTION object

JavaScript syntax:

-

myTABLE.caption

This property yields a reference to a CAPTION object belonging to the table. That is if you have defined a caption with the HTML tag.

Warnings: ❑

This property is not fully supported on all versions of the MSIE browser or across all platforms. See also:

CAPTION object

Property attributes: ReadOnly.

2173

JavaScript Programmer's Reference

TABLE.cellPadding (Property) The width of the cell padding around the cell contents within a table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTABLE.cellPadding

The cell padding describes the space allowed inside the cell but around the cell content. The table grows larger but the border thicknesses stay the same. The growth takes place inside the cells.

TABLE.cells[] (Collection) A collection of all the cells in a . Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Collection object

JavaScript syntax:

IE

myTABLE.rows

This collection includes any cells inside objects instantiated by , and tags. This is not necessarily the same as the cells collection returned from a TBODY object. Addressing the table by means of its cells[] collection allows you to visit all the cells in a single enumeration loop rather than having to nest a loop for each axis of the table. The columns and rows are different axes of the table. However, they are described in different ways. The cols value is simply an integer that is set to the number of columns. The rows property is a reference to a collection of objects, one row object for each row in the table. Therefore to establish how many cells there are in the table, you need to multiply the table.cols value by the table.rows.length value. The table.cols value should also be equivalent to table.rows.cells.length value as well. See also:

Property attributes: ReadOnly.

2174

Collection object, TABLE.cols, TABLE.rows[], TBODY.rows[], TFOOT.rows[], THEAD.rows[], TR.rowIndex

T – TABLE.cellSpacing (Property)

TABLE.cellSpacing (Property) The width of the cell spacing between cells in a table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTABLE.cellSpacing

The cell spacing describes the space allowed between adjacent table cells. This moves the cells apart by introducing a few pixels outside the cell border. It has the effect of thickening the border lines between cells.

TABLE.cols (Property) The number of columns in a table. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTABLE.cols

The columns and rows are different axes of the table. However, they are described in different ways. The cols value is simply an integer that is set to the number of columns. The rows property is a reference to a collection of objects, one row object for each row in the table. Therefore to establish how many cells there are in the table, you need to multiply the table.cols value by the table.rows.length value. The table.cols value should also be equivalent to the table.rows.cells.length value. See also:

style.columnSpan, TABLE.cells[], TABLE.rows[], TBODY.rows[], TFOOT.rows[], THEAD.rows[], TR.cells[]

TABLE.createCaption() (Method) Creates a new CAPTION object for use with the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

2175

JavaScript Programmer's Reference

Property/method value type:

CAPTION object

JavaScript syntax:

-

myTABLE.createCaption()

You can modify a caption by accessing its innerHTML property in MSIE and Netscape 6.0. See also:

CAPTION object

TABLE.createTFoot() (Method) Creates a new TFOOT object for use with the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

TFOOT object

JavaScript syntax:

-

See also:

TFOOT object

myTABLE.createTFoot()

TABLE.createTHead() (Method) Creates a new THEAD object for use with the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

THEAD object

JavaScript syntax:

-

See also:

THEAD object

2176

myTABLE.createTHead()

T – TABLE.dataPageSize (Property)

TABLE.dataPageSize (Property) Part of the data-binding model in MSIE that maps table rows to database rows. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTABLE.dataPageSize

This is used in MSIE when the contents of a table are instantiated from a database fetch. Each row corresponds to a record and the columns correspond to a field in the record structure. This property determines how many records are assumed to be in each page full of data. That way the table can be traversed one full page at a time. The nextPage() and previousPage() methods are used to aid navigation of a table that is paged in this manner. See also:

TABLE.nextPage(), TABLE.previousPage(), TABLE.refresh()

TABLE.deleteCaption() (Method) Deletes the CAPTION object currently belonging to the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

See also:

CAPTION object

myTABLE.deleteCaption()

TABLE.deleteRow() (Method) Deletes a specified row within the TABLE object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

myTABLE.deleteRow(anIndex)

Argument list:

anIndex

The row to delete

See also:

TR object

2177

JavaScript Programmer's Reference

TABLE.deleteTFoot() (Method) Deletes the table footer from the owning table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

See also:

TFOOT object

myTABLE.deleteTFoot()

TABLE.deleteTHead() (Method) Deletes the table header from the owning table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

See also:

THEAD object

myTABLE.deleteTHead()

TABLE.frame (Property) A control over which of the table cells sides are controlled by the BORDER tag attribute and border property of the TABLE object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

2178

myTABLE.frame

T – TABLE.height (Property)

This property controls which parts of a table's outer framing border are rendered into the display. The following keywords are supported by this property: Keyword

Description

above

The top edge only

below

The bottom edge only

border

All four sides

box

Same as border

hsides

Top and bottom edges

lhs

Left edge

rhs

Right edge

void

No sides framed at all

vsides

Left and right sides

The frame property affects the outer border around the whole table. You should use the border property to control the ruled edges between cells. See also:

TABLE.border, TABLE.rules

TABLE.height (Property) The height of the TABLE in pixels. Availability:

JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTABLE.height

A table will be sized according to the content within it. The HTML tags for a table allow the table height to be specified as a percentage of the height of the containing HTML element. When the table is rendered, an extent rectangle can be drawn round it. An extent rectangle is the smallest rectangle that will completely enclose the table. This height property returns the vertical size of that extent rectangle. Including height and width information on tables is optional, but it can significantly improve the performance of the layout engine as it renders the web page. This is because the layout engine does not need to wait until the table content has all been fetched before reserving sufficient space for it in the display. See also:

TABLE.width

2179

JavaScript Programmer's Reference

TABLE.insertRow() (Method) Insert a new row into the table at a specified row index. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

TR object

JavaScript syntax:

-

myTABLE.insertRow(anIndex)

Argument list:

anIndex

The row at which to insert a new row

See also:

TR object

TABLE.nextPage() (Method) Part of the data binding mechanism that pages the table according to the contents of a database selection. Availability:

JScript – 3.0 Internet Explorer – 4.0

JavaScript syntax:

IE

myTABLE.nextPage()

When this method is called from your script, the data handler will load the next group of records from the data source and display them in the table cells. The number of records fetched from the database corresponds to the dataPageSize property. See also:

TABLE.dataPageSize, TABLE.previousPage(), TABLE.refresh()

TABLE.previousPage() (Method) Part of the data binding mechanism that pages the table according to the contents of a database selection. Availability:

JScript – 3.0 Internet Explorer – 4.0

JavaScript syntax:

IE

myTABLE.previousPage()

When this method is called from your script, the data handler will load the previous group of records from the data source and display them in the table cells. The number of records fetched from the database corresponds to the dataPageSize property. See also:

2180

TABLE.dataPageSize, TABLE.nextPage(), TABLE.refresh()

T – TABLE.refresh() (Method)

TABLE.refresh() (Method) Part of the data binding mechanism that refreshes the table according to the contents of a database selection. Availability:

JScript – 3.0 Internet Explorer – 4.0

JavaScript syntax:

IE

myTABLE.refresh()

When this method is called from your script, the data handler will load the current group of records from the data source and display them in the table cells. The number of records fetched from the database corresponds to the dataPageSize property. This might be useful if the database is a means of communicating between several users who are accessing the data at the same time. You might set up some means of refreshing automatically with a timeout loop. See also:

TABLE.dataPageSize, TABLE.nextPage(), TABLE.previousPage()

TABLE.rows[] (Collection) A collection of all the rows in a
. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Collection object

JavaScript syntax:

-

myTABLE.rows

This collection includes any rows inside objects instantiated by , and tags. This is not necessarily the same as the rows collection returned from a TBODY object. The columns and rows are different axes of the table. However they are described in different ways. The cols value is simply an integer that is set to the number of columns. The rows property is a reference to a collection of objects, one row object for each row in the table. Therefore to establish how many cells there are in the table, you need to multiply the table.cols value by the table.rows.length value. The table.cols value should also be equivalent to table.rows.cells.length value. See also:

Collection object, TABLE.cells[], TABLE.cols, TBODY.rows[], TFOOT.rows[], THEAD.rows[], TR.rowIndex

Property attributes: ReadOnly.

2181

JavaScript Programmer's Reference

TABLE.rules (Property) Controls the drawing of border rules around table cells. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTABLE.rules

This property controls which parts of a table's inner borders are rendered into the display. The following keywords are supported by this property: Keyword

Description

all

All borders are placed around all cells

cols

Borders only delimit columns of cells

groups

Borders are placed between cell groups

none

No borders between cells are displayed at all

rows

Borders only delimit rows

Where borders are used to delimit groups of cells, the groups are established with the , , , or HTML tags. The rules property affects the inner borders around the cells in the table. The frame property controls the ruled edges around the outside of the table. Table ruling and bordering is quite complex and some time spent messing around with the property values is worthwhile.

Warnings: ❑

Be careful not to confuse this with the rules[] collection of a StyleSheet. These rules are ruled borders not style sheet rules. See also:

2182

COL object, COLGROUP object, TABLE.frame, TBODY object, TFOOT object, THEAD object

T – TABLE.summary (Property)

TABLE.summary (Property) Adds a summary text object to the table. Availability:

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

N

myTABLE.summary

This is a textual summary of the table for presentation where the table cannot be rendered out. Braille browsers or speaking browsers for the sight impaired would utilize this and it might be useful as a mouse rollover tooltip text.

TABLE.tBodies[] (Collection) A collection of all TBODY objects within a table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Collection object

JavaScript syntax:

-

myTABLE.tBodies

If a table has any HTML tags defined within its extent, then the TBODY objects instantiated by those tags will become members of this collection. See also:

TABLE object, TBODY object

Property attributes: ReadOnly.

TABLE.tFoot (Property) A reference to a TFOOT object for the table if there is one defined. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

TFOOT object

JavaScript syntax:

-

myTABLE.tFoot

2183

JavaScript Programmer's Reference

If a table has a HTML tag defined within its extent, then the TFOOT object instantiated by those tags can be accessed via this property. Note that a table can own only one TFOOT object. See also:

TABLE object, TFOOT object

Property attributes: ReadOnly.

TABLE.tHead (Property) A reference to a THEAD object for the table if there is one defined. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

THEAD object

JavaScript syntax:

-

myTABLE.tHead

If a table has a HTML tag defined within its extent, then the THEAD object instantiated by those tags can be accessed via this property. Note that a table can own only one THEAD object. See also:

TABLE object, THEAD object

Property attributes: ReadOnly.

TABLE.width (Property) The width of the TABLE in pixels. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

2184

myTABLE.width

T – TableColElement object (Object/HTML)

A table will be sized according to the content within it. The HTML tags for the table allow the table width to be specified as a percentage of the width of the containing HTML element. When the table is rendered, an extent rectangle can be drawn round it. An extent rectangle is the smallest rectangle that will completely enclose the table. This width property returns the horizontal size of that extent rectangle. Including height and width information on tables is optional but it can significantly improve the performance of the layout engine as it renders the web page. This is because the layout engine does not need to wait until the table content has all been fetched before reserving sufficient space for it in the display. TABLE.height

See also:

TableColElement object (Object/HTML) A means of accessing cells in a particular column of the table without needing to traverse the rows. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Inherits from:

Element object

JavaScript syntax:

-

Object properties:

align, ch, chOff, span, vAlign, width

Event handlers:

onClick, onDblClick, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp

See also:

COL object, COLGROUP object, TABLE object

myTableColElement = new TableColElement()

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

align ch chOff span vAlign width

1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 +

5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 +

6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 +

5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 +

-

1+ 1+ 1+ 1+ 1+ 1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

5.0 + 5.0 +

6.0 + 6.0 +

5.0 + 5.0 +

-

4.0 + Warning 4.0 + Warning Table continued on following page

onClick 1.5 + onDblClick 1.5 +

2185

JavaScript Programmer's Reference

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp

1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 + 1.5 +

5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 +

6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 + 6.0 +

5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 + 5.0 +

-

-

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

Warning Warning Warning Warning Warning Warning Warning Warning Warning

Inheritance chain Element object, Node object

TableColElement.align (Property) The alignment settings for a column or column group in the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

See also:

COL object, COLGROUP object, TABLE object

myTableColElement.align

TableColElement.ch (Property) The alignment character for cells in the column. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

See also:

COL object, COLGROUP object, TABLE object

2186

myTableColElement.ch

T – TableColElement.chOff (Property)

TableColElement.chOff (Property) The offset of the alignment character. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

See also:

COL object, COLGROUP object, TABLE object

myTableColElement.chOff

TableColElement.span (Property) The number of columns that a column group should span. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

See also:

COL object, COLGROUP object, TABLE object

myTableColElement.span

TableColElement.vAlign (Property) The vertical alignment setting for a column within the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

See also:

COL object, COLGROUP object, TABLE object

myTableColElement.vAlign

2187

JavaScript Programmer's Reference

TableColElement.width (Property) The width of a column within the table. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

See also:

COL object, COLGROUP object, TABLE object

myTableColElement.width

TableSectionElement object (Object/DOM) DOM level 1 specifies a single object that MSIE implements as TFOOT and THEAD objects. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

JavaScript syntax:

-

See also:

THEAD object, TFOOT object

myTableSectionElement = new TableSectionElement()

tags (Property) An alternative reference to the document.tags property in JSS. Availability:

JavaScript – 1.2 Netscape – 4.0 Deprecated in Netscape 6.0

Property/method value type:

Collection object

JavaScript syntax:

N

myDocument.tags

Warnings: ❑

This functionality is removed from Netscape 6.0. See also:

2188

JavaScript Style Sheets, Document.tags[]

T – taint() (Function/global)

taint() (Function/global) A method for controlling secure access to data values. Availability:

JavaScript – 1.1 Netscape – 3.0 Deprecated

This was removed at version 1.2 of JavaScript. If you encounter it in a script you are maintaining, it is probably wise to seek how it can be removed, otherwise it is likely to cause a run-time error.

Warnings: ❑

DO NOT USE THIS FUNCTION! See also:

Navigator.taintEnabled(), untaint()

TBODY object (Object/HTML) An object that encapsulates a tag within a
block. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Inherits from:

Element object

JavaScript syntax:

IE

myTBODY = myDocument.all.anElementID

IE

myTBODY = myDocument.all.tags("TBODY")[anIndex]

IE

myTBODY = myDocument.all[aName]

-

myTBODY = myDocument.getElementById(anElementID) myTBODY = myDocument.getElementsByName (aName)[anIndex] myTBODY = myTable.tBodies[anIndex]

HTML syntax: Argument list:

Object properties:

myTBODY = myDocument.getElementsByTagName ("TBODY")[anIndex]

... anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

accessKey, align, bgColor, chOff, rows, tabIndex, vAlign

2189

JavaScript Programmer's Reference

Event handlers:

onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

Collections:

rows[]

Each table owns at least one TBODY object which is created by default even if you don't enclose some rows within tags. Additional TBODY objects can be created to break the table into sections if you need to. The TBODY object represents that part of the table which excludes any footer or header cells. You can access TBODY objects by their ID HTML tag attribute in the DOM hierarchy or by selecting them from the tBodies[] collection belonging to their parent TABLE object.

Warnings: ❑

Note that on some versions of the MSIE browser on the Macintosh platform, you cannot access the innerHTML, innerText, outerHTML or outerText properties of a TBODY object. See also:

Element object, Input.accessKey, TABLE object, TABLE.rules, TABLE.tBodies[], TD object, TR object

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

accessKey

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

align

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

bgColor

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

chOff

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

rows

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

tabIndex

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

vAlign

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onClick

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onDblClick

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onDragStart

-

3.0 +

-

4.0 +

-

-

-

-

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

onKeyDown

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onKeyPress

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onKeyUp

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseDown

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseMove

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

Table continued on following page

2190

T – TBODY.align (Property)

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onMouseOut

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOver

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseUp

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Node object

TBODY.align (Property) A control for the alignment of cells within the TBODY object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTBODY.align

The alignment of the TBODY object with respect to its containing parent object is defined in this property. The available set of alignment specifiers include: ❑

center



left



right



char



justify See also:

TABLE.align, TD.align, TFOOT.align, TH.align, THEAD.align, TR.align

TBODY.bgColor (Property) The background color of a TBODY object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

2191

JavaScript Programmer's Reference

Property/method value type:

String primitive

JavaScript syntax:

-

myTBODY.bgColor

The background can be colored independently of whether an image is loaded into the background of an object. In fact it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:

Color names, Color value

TBODY.rows[] (Collection) A collection of objects, each one containing a description of a row described by a tag. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

JavaScript syntax:

-

myTBODY.rows

This is not necessarily the same as the rows collection returned from a TABLE object. That is because the rows[] collection belonging to a TBODY object can only list those TR objects that are contained within the tags. See also:

Collection object, TABLE.cells[], TABLE.cols, TABLE.rows[], TFOOT.rows[], THEAD.rows[], TR.rowIndex

Property attributes: ReadOnly.

TBODY.vAlign (Property) A control for the vertical alignment of cells within the TBODY object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

2192

myTBODY.vAlign

T – TD object (Object/HTML) The vertical alignment of the content within the table cells can be controlled across an entire TBODY extent with this property. The following keywords can be assigned to it: ❑

baseline



bottom



middle



top

These may be also available on some implementations: ❑

absbottom



absmiddle



baseline



texttop See also:

TD.vAlign, TFOOT.vAlign, TH.vAlign, THEAD.vAlign, TR.vAlign

TD object (Object/HTML) An object that encapsulates a single cell described by a anIndex

A reference to an element in a collection

aName

An associative array reference

anElementID

The ID value of an Element object

abbr, accessKey, align, axis, background, bgColor, borderColor, borderColorDark, borderColorLight, cellIndex, ch, chOff, colSpan, headers, height, noWrap, rowSpan, scope, tabIndex, vAlign, width

2193

JavaScript Programmer's Reference

Event handlers:

onAfterUpdate, onBeforeUpdate, onBlur, onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onResize, onRowEnter, onRowExit, onSelectStart

This object is instantiated by a
tag. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Inherits from:

Element object

JavaScript syntax:

IE

myTD = myDocument.all.anElementID

IE

myTD = myDocument.all.tags("TD")[anIndex]

IE

myTD = myDocument.all[aName]

-

myTD = myDocument.getElementById(anElementID)

-

myTD = myDocument.getElementsByName (aName)[anIndex] myTD = myDocument.getElementsByTagName ("TD")[anIndex]

HTML syntax: Argument list:

Object properties:

... tag that encloses the content of a single data cell. Some of the property values in this object may be inherited from parent objects such as TABLE, TR and TBODY.

Warnings: ❑

Note that on some versions of the MSIE browser on the Macintosh platform, you cannot access the innerHTML, innerText, outerHTML or outerText properties of a TD object. See also:

Element object, Input.accessKey, TABLE object, TBODY object, TH object, TR object

Property

JavaScript

abbr accessKey

JScript

N

DOM HTML

Notes

1.5 +

-

6.0 +

-

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

-

1+

-

align

Warning

1.5 +

3.0 +

6.0 +

axis

1.5 +

-

6.0 +

4.0 +

-

1+

-

-

-

-

1+

-

background

-

-

3.0 +

bgColor

1.5 +

3.0 +

-

4.0 +

-

-

-

-

6.0 +

4.0 +

-

1+

-

-

borderColor

-

3.0 +

borderColorDark

-

3.0 +

-

4.0 +

-

-

-

-

-

4.0 +

-

-

-

-

borderColorLight

-

cellIndex

1.5 +

3.0 +

-

4.0 +

-

-

-

-

3.0 +

6.0 +

4.0 +

-

1+

-

Warning, ReadOnly

ch chOff

1.5 +

-

6.0 +

-

-

1+

-

-

1.5 +

-

6.0 +

-

-

1+

-

-

colSpan

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

headers

1.5 +

-

6.0 +

-

-

1+

-

-

height

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

noWrap

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

rowSpan

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

scope

1.5 +

-

6.0 +

-

-

1+

-

-

tabIndex

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

Warning

vAlign

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

width

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

2194

IE

Opera

T – TD.abbr (Property)

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onAfterUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBeforeUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBlur

1.5 +

3.0 +

6.0 +

4.0 +

-

-

-

Warning

onClick

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onDblClick

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onDragStart

-

3.0 +

-

4.0 +

-

-

-

-

onFilterChange

-

3.0 +

-

4.0 +

-

-

-

-

onHelp

-

3.0 +

-

4.0 +

-

-

-

Warning

onKeyDown

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onKeyPress

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onKeyUp

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseDown

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseMove

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOver

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onMouseUp

1.5 +

3.0 +

6.0 +

4.0 +

-

-

4.0 +

Warning

onResize

1.5 +

3.0 +

6.0 +

4.0 +

-

-

-

Warning

onRowEnter

-

3.0 +

-

4.0 +

-

-

-

-

onRowExit

-

3.0 +

-

4.0 +

-

-

-

-

onSelectStart

-

3.0 +

-

4.0 +

-

-

-

-

Inheritance chain: Element object, Node object

TD.abbr (Property) An abbreviation value to be used for header cells in the column where the data cell resides. Availability:

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

N

See also:

TH.abbr

myTD.abbr

2195

JavaScript Programmer's Reference

TD.align (Property) A control for the alignment of content within the table cell. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTD.align

The alignment of the TD object with respect to its containing parent object is defined in this property. The following set of alignment specifiers are available: ❑

center



left



right



char



justify See also:

TABLE.align, TBODY.align, TFOOT.align, TH.align, THEAD.align, TR.align

TD.axis (Property) The names group of related header cells. Availability:

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

N

See also:

TH.axis

2196

myTD.axis

T – TD.background (Property)

TD.background (Property) A URL for an image to be loaded into the background of the table cell. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTD.background

If a background image is available, then its URL is contained in this property. Changing the value in this property will replace the background with a new one. However there may be a perceptible delay while the new image is fetched from the web server. You might be able to work around that by preloading the image and keeping a reference to it in a variable. See also:

TH.background

TD.bgColor (Property) The background color for this table cell. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTD.bgColor

The background can be colored independently of whether an image is loaded into the background of an object. In fact it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:

Color names, Color value, TH.bgColor

TD.borderColor (Property) The color of the border around this table cell. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTD.borderColor

2197

JavaScript Programmer's Reference

You can use this property to determine the color of a border surrounding a table data cell. Note that there are additional properties to determine the highlights and lowlights of the table data cell border coloring. See also:

TH.borderColor

TD.borderColorDark (Property) The color value of the shadowed edge of the table cell border (assuming the table is lit from the top left). Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTD.borderColorDark

Table data cell borders are presented as having an engraved appearance. This means you may need to control the highlights and lowlights. This property defines the color of the shadowed part of the table data cell border. See also:

TH.borderColorDark

TD.borderColorLight (Property) The color value of the highlighted edge of the table cell border (assuming the table is lit from the top left). Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTD.borderColorLight

Table data cell borders are presented as having an engraved appearance. This means you may need to control the highlights and lowlights. This property defines the color of the highlighted part of the table data cell border. See also:

TH.borderColorLight

TD.cellIndex (Property) A zero-based integer value that indicates the position of this cell within the row. This is the horizontal coordinate position of the cell within the table.

2198

T – TD.ch (Property)

Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myTD.cellIndex

You can access cells by means of the rows[] and cells[] collections belonging to the TABLE and TR objects respectively. This property provides the horizontal coordinate to use in the TR.cells[] collection to access the object describing this table cell.

Warnings: ❑

This is not supported on some versions of MSIE running on the Macintosh platform. See also:

TH.cellIndex

Property attributes: ReadOnly.

TD.ch (Property) The alignment character for cells in a column arrangement. Availability:

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

N

myTD.ch

HTML 4.0 provides for text to be arranged in neat columns within table cells without the need to create additional tables within tables. This method of alignment is selected by setting the ALIGN="CHAR" HTML tag attribute. The CHAR="..." HTML tag attribute is reflected in this property and is active when the CHAROFF="..." HTML tag attribute is present. See also:

COL.ch, COLGROUP.ch, TH.ch, THEAD.ch, TR.ch

2199

JavaScript Programmer's Reference

TD.chOff (Property) The offset of a column alignment character. Availability:

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

N

myTD.chOff

The CHAR alignment style requires that an alignment character be specified with the ch property and that an offset measured in pixels be defined as its value. The offset value can be defined with the CHAROFF HTML tag attribute. The remainder of the string is offset by this distance from the alignment character. See also:

COL.chOff, COLGROUP.chOff, TH.chOff, THEAD.chOff, TR.chOff

TD.colSpan (Property) The number of columns that the table cell spans. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myTD.colSpan

This corresponds to the COLSPAN attribute within a
HTML tag for a table cell description. It defines how many table columns this column is to span.

Warnings: ❑

Note that this may affect the value of the cellIndex property for subsequent cells within the same row. Although you cannot alter the cellIndex value directly, operations that affect the way the table is addressed may move cells around in the collection that represents all cells in the table. See also:

2200

COL.span, COLGROUP.span, style.columnSpan, TH.colSpan

T – TD.headers (Property)

TD.headers (Property) A list of ID attribute values for header cells. Availability:

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

N

See also:

TH.headers

myTD.headers

TD.height (Property) The height in pixels of the table cell. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTD.height

The table cell space is defined by an extent rectangle that surrounds the space occupied by it on the screen. An extent rectangle is that smallest rectangle that completely encloses the item. This property specifies the height of that extent rectangle. See also:

TH.height

TD.noWrap (Property) Controls whether textual content is allowed to wrap within the table cell. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Boolean primitive

JavaScript syntax:

-

myTD.noWrap

2201

JavaScript Programmer's Reference

This is a Boolean value that controls whether the textual content is wrapped at the right hand window border or not. If the value false is assigned to this property, then words will wrap as the page is drawn. This is good and is the way you would expect a browser to behave. The text will flow according to the space available. If the value true is assigned to this property, the line of text will continue to the right until a
or other block level tag is encountered. This will force the horizontal width of the page to be extremely large and the user will need to scroll furiously to be able to see the text and then scroll back again for the start of the next line.

Warnings: ❑

Only use this if you plan to place line breaks at frequent intervals yourself and really do need to control the line breaks manually. The effect is as if you had placed tags around the content of the cell, although the font may still be a proportional font rather than the monospaced font that sets up by default. See also:

TH.noWrap

TD.rowSpan (Property) Indicates how many rows the table cell is intended to span. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myTD.rowSpan

This is used when you want to create complex tables. This technique may be an alternative to nesting a table. That is always good because sometimes nested tables can become very unwieldy. See also:

style.rowSpan, TH.rowSpan

TD.scope (Property) The scope covered by header cells. Availability:

2202

DOM level – 1 JavaScript – 1.5 Netscape – 6.0

T – TD.vAlign (Property)

Property/method value type:

String primitive

JavaScript syntax:

N

See also:

TH.scope

myTD.scope

TD.vAlign (Property) The vertical alignment of content within the table cell. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTD.vAlign

The vertical alignment of the content within the table cells can be controlled for a single table cell with this property. The following keywords can be assigned to it: ❑

baseline



bottom



middle



top

These may be also available on some implementations: ❑

absbottom



absmiddle



baseline



texttop

This value will override the setting for a row or TBODY extent. See also:

TBODY.vAlign, TFOOT.vAlign, TH.vAlign, THEAD.vAlign, TR.vAlign

2203

JavaScript Programmer's Reference

TD.width (Property) The width in pixels of the table cell. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTD.width

The table cell space is defined by an extent rectangle that surrounds the space occupied by it on the screen. An extent rectangle is that smallest rectangle that completely encloses the item. This property specifies the width of that extent rectangle. See also:

TH.width

telnet: URL (Request method) Opens up a telnet client to do terminal mode access. Open a telnet application and connect to the telnet port on the target server. You should be asked for a username and password. This will then give you access to a command line interface on the target host as long as you are validated. See also:

javascript: URL, mailbox: URL, Security policy, URL

Ternary operator (Definition) An operator that requires three arguments. There is only one ternary operator in JavaScript. It is the ?: conditional execution operator. See also:

Cross-references: Wrox Instant JavaScript – page – 18 Wrox Instant JavaScript – page – 21

2204

Binary operator, Conditionally execute (?:), Unary operator

T – Text object (Object/DOM)

Text object (Object/DOM) The DOM level 1 specification describes a Text object which MSIE and Netscape 6.0 implement as a textNode object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

JavaScript syntax:

-

myText = new Text()

Refer to: textNode object

text/JavaScript (MIME type) A MIME type that indicates the content is a JavaScript source text. This is otherwise known as application/x-javascript, although text/JavaScript should be used. See also:



2206

T – TEXTAREA object (Object/DOM)

See also:

Element object, Element.isTextEdit, Form.elements[], Input object, Input.accessKey, onChange, onKeyDown, onKeyPress, onKeyUp, TEXTAREA.handleEvent(), TextRange object

Property

JavaScript

JScript

N

IE

Opera DOM

HTML

Notes

cols

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

readOnly

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

ReadOnly

rows

1.5 +

3.0 +

6.0 +

4.0 +

-

1+

-

-

type

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

1+

-

ReadOnly

value

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

1+

-

-

wrap

-

3.0 +

-

4.0 +

-

-

-

-

Method

JavaScript

JScript

N

IE

Opera DOM

HTML

Notes

handleEvent()

1.2 +

-

4.0 +

-

-

-

-

-

select()

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera DOM

HTML

Notes

onAfterUpdate onBeforeUnload onBeforeUpdate onBlur onChange onDragStart onErrorUpdate onFilterChange onFocus onHelp onKeyDown onKeyPress onKeyUp onMouseDown onMouseMove onMouseOut onMouseOver onMouseUp onRowEnter onRowEnter? onRowExit onScroll onSelect onSelectStart

1.1 + 1.0 + 1.0 + 1.2 + 1.2 + 1.2 + 1.2 + 1.2 + 1.1 + 1.0 + 1.2 + 1.0 + 1.0 + -

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 1.0 + 3.0 + 3.0 + 1.0 + 3.0 + 3.0 + 3.0 + 3.0 +

3.0 + 2.0 + 2.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.0 + 2.0 + 4.0 + 2.0 + 2.0 + -

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 3.02 + 4.0 + 4.0 + 3.02 + 4.0 + 4.0 + 4.0 + 4.0 +

3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + -

4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + -

Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning Warning -

1+ -

2207

JavaScript Programmer's Reference

Inheritance chain: Element object, Input object, Node object

TEXTAREA.cols (Property) The number of columns that a TextArea may contain. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myTEXTAREA.cols

The text area in a form is sized by columns and rows in the default font used for input items. This property reflects the COLS HTML tag attribute in the HTML tag that instantiates this object. Style sheets are about the only way you can control the appearance of these cells because it is the only way the default input font can be changed. If the font size changes then the size of the TEXTAREA extent rectangle must change too. This might affect the layout of the page.

TEXTAREA.handleEvent() (Method) Passes an event to the appropriate handler for this object. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

undefined

JavaScript syntax:

N

myTEXTAREA.handleEvent(anEvent)

Argument list:

anEvent

An event to be handled by this object

This applies to Netscape prior to version 6.0. From that release onwards, event management follows the guidelines in the DOM level 3 event specification. On receipt of a call to this method, the receiving object will look at its available set of event handler functions and pass the event to an appropriately mapped handler function. It is essentially an event dispatcher that is granular down to the object level. The argument value is an Event object that contains information about the event. See also:

2208

TEXTAREA object, Window.handleEvent()

T – TEXTAREA.readOnly (Property)

TEXTAREA.readOnly (Property) When set to true, the TextArea cannot be modified. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Boolean value

JavaScript syntax:

-

myTEXTAREA.readOnly

The TextArea content is defined but cannot be changed by the user. You may want to control this property based on JavaScript code. If the property is set true from the HTML document source, you will have to unlock the field before the user can modify the field content. See also:

Input.readOnly, Password.readOnly, TextCell.readOnly

Property attributes: ReadOnly.

TEXTAREA.rows (Property) The number of rows in a text area. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myTEXTAREA.rows

The text area in a form is sized by columns and rows in the default font used for input items. This property reflects the ROWS HTML tag attribute in the HTML tag that instantiates this object. Style sheets are about the only practical way you can control the appearance of these cells because it is the only way the default input font can be changed. If the font size changes then the size of the TEXTAREA extent rectangle must change too. This might affect the layout of the page.

2209

JavaScript Programmer's Reference

TEXTAREA.select() (Method) Selects all the text within the cell allowing it to be cut and pasted by the user. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera browser – 3.0

JavaScript syntax:

-

myTEXTAREA.select()

If the browser supports a Selection object or TextRange objects, you may then be able to access the selected text using JavaScript. Of course in a form object, the text of the whole object can also be accessed, but this may not be what was selected because the user may select all or part of a page, and that selection may span several form elements or be only part of a form element. See also:

Input.select()

TEXTAREA.type (Property) The type indicator for this Input object. Availability:

DOM level – 1 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTEXTAREA.type

This property is supported to remain consistent with all other form elements. The value returned by a TEXTAREA object should always be "textarea". This allows you to determine the input type when the form elements array is traversed. Then you can select appropriate handling based on the type value for the element. See also:

Property attributes: ReadOnly.

2210

Input.type

T – TEXTAREA.value (Property)

TEXTAREA.value (Property) The text string that has been entered into the text area. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTEXTAREA.value

This may be the same as the defaultValue if the user has not yet entered any text into the TEXTAREA. See also:

Input.value, TextCell.value

TEXTAREA.wrap (Property) Controls the kind of word wrapping effect within the text area. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTEXTAREA.wrap

You would normally want the text to wrap within a text area field so that you could see it all. However there may be times when other text wrapping regimes could be useful. This property will accept the following keywords: ❑

off



physical



virtual

The off keyword switches word wrapping off altogether. The physical keyword wraps text as it reaches the right border. It will also send the carriage returns back to the server when the form data is submitted. The virtual keyword shows the word wrapping effect on the screen but the carriage returns are not sent back to the server which remains unaware that any wrapping has occurred. This is probably the most useful setting.

2211

JavaScript Programmer's Reference

TextCell object (Object/DOM) A single line text cell in a form. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0

Inherits from:

Input object

JavaScript syntax:

-

myTextCell = myDocument.aFormName.anElementName

IE

myTextCell = myDocument.aFormName.elements[anItemIndex] myTextCell = myDocument.all.anElementID

IE

myTextCell = myDocument.all.tags("INPUT")[anIndex]

IE

myTextCell = myDocument.all[aName]

-

myTextCell = myDocument.forms[aFormIndex].anElementName myTextCell = myDocument.forms[aFormIndex].elements [anItemIndex] myTextCell = myDocument.getElementById(anElementID)

HTML syntax: Argument list:

myTextCell = myDocument.getElementsByName(aName) [anIndex] myTextCell = myDocument.getElementsByTagName ("INPUT")[anIndex]

anIndex

A valid reference to an item in the collection

aName

The NAME attribute of an element

anElementID

The ID attribute of an element

anItemIndex

A valid reference to an item in the collection

aFormIndex

A reference to a particular form in the forms collection

Object properties:

maxLength, readOnly, size, type, value

Object methods:

handleEvent(), select()

Event handlers:

onAfterUpdate, onBeforeUpdate, onBlur, onChange, onFilterChange, onFocus, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onRowEnter, onRowExit, onSelect

Many properties, methods and event handlers are inherited from the Input object class. Refer to topics grouped with the "Input" prefix for details of common functionality across all sub-classes of the Input object super-class.

2212

T – TextCell object (Object/DOM) There isn't really a TextCell object class, but it is helpful when trying to understand the wide variety of input element types if we can reduce the complexity by discussing only the properties and methods of a text cell. In actual fact, the object is represented as an item of the Input object class. Event handling support via properties containing function objects was added to TextCell objects at version 1.1 of JavaScript. The Netscape implementation of this sub-class of the Input object does not support as wide a variety of events as the MSIE implementation. In particular, the keyboard events are not supported. The WebTV set-top box does not support the onkeypress event handler for this object type prior to the Summer 2000 release.

Example code:



?










See also:

Element object, Element.isTextEdit, Form.elements[], FormElement object, Input object, Input.accessKey, JellyScript, onChange, onKeyDown, onKeyPress, onKeyUp, TextCell.handleEvent(), TextRange object

Property

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

maxLength

-

3.0 +

-

4.0 +

-

-

-

-

readOnly

-

3.0 +

-

4.0 +

-

-

-

ReadOnly

size

-

3.0 +

-

4.0 +

-

-

-

Warning

type

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

1+

-

ReadOnly

value

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

1+

-

-

2213

JavaScript Programmer's Reference

Method

JavaScript

JScript

N

handleEvent() select()

IE

Opera

DOM

HTML

Notes

1.2 +

-

4.0 +

-

1.0 +

1.0 +

2.0 +

3.02 +

-

-

-

-

3.0 +

1+

-

-

Event name

JavaScript

JScript

N

IE

Opera

DOM

HTML

Notes

onAfterUpdate

-

3.0 +

-

4.0 +

-

-

-

-

onBeforeUpdate

-

3.0 +

onBlur

-

4.0 +

-

-

-

-

1.1 +

onChange

1.0 +

3.0 +

3.0 +

4.0 +

3.0 +

-

-

Warning

3.0 +

2.0 +

4.0 +

3.0 +

-

-

onFilterChange

-

-

onFocus

1.0 +

3.0 +

-

4.0 +

-

-

-

-

3.0 +

2.0 +

4.0 +

3.0 +

-

-

onHelp

Warning

-

onKeyDown

1.2 +

3.0 +

-

4.0 +

-

-

-

Warning

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

onKeyPress

Warning

onKeyUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseDown

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseMove

1.2 +

3.0 +

4.0 +

4.0 +

-

-

4.0 +

Warning

onMouseOut

1.1 +

3.0 +

3.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onMouseOver

1.0 +

1.0 +

2.0 +

3.02 +

3.0 +

-

4.0 +

Warning

onMouseUp

1.2 +

3.0 +

4.0 +

4.0 +

3.0 +

-

4.0 +

Warning

onRowEnter

-

3.0 +

-

4.0 +

-

-

-

-

onRowExit

-

3.0 +

-

4.0 +

-

-

-

-

onSelect

1.0 +

3.0 +

2.0 +

4.0 +

3.0 +

-

-

-

Inheritance chain: Element object, Input object, Node object

TextCell.handleEvent() (Method) Pass an event to the appropriate handler for this object. Availability:

JavaScript – 1.2 Netscape – 4.0

Property/method value type:

undefined

JavaScript syntax:

N

myTextCell.handleEvent(anEvent)

Argument list:

anEvent

An event to be handled by this object

This applies to Netscape prior to version 6.0. From that release onwards, event management follows the guidelines in the DOM level 3 event specification.

2214

T – TextCell.maxLength (Property)

On receipt of a call to this method, the receiving object will look at its available set of event handler functions and pass the event to an appropriately mapped handler function. It is essentially an event dispatcher that is granular down to the object level. The argument value is an Event object that contains information about the event. See also:

TextCell object, Window.handleEvent()

TextCell.maxLength (Property) The maximum length of values to be entered into the text cell. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTextCell.maxLength

This defines the maximum number of characters that are allowed to be entered into the text field. The browsers differ in how they handle this value. Some will warn the user with a beep or flash on the screen, others simply stop accepting keystrokes when this number of characters have been entered. See also:

Input.maxLength, Password.maxLength

TextCell.readOnly (Property) When set to true, the text cell contents cannot be changed. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Boolean primitive

JavaScript syntax:

IE

myTextCell.readOnly

The TextCell content is defined but cannot be changed by the user. You may want to control this property based on JavaScript code. If the property is set true from the HTML document source, you will have to unlock the field before the user can modify the field content. See also:

Input.disabled, Input.readOnly, Password.readOnly, TEXTAREA.readOnly

Property attributes: ReadOnly.

2215

JavaScript Programmer's Reference

TextCell.select() (Method) Selects all the textual content of a text cell allowing the user to cut and paste it if they so wish. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0

JavaScript syntax:

-

myTextCell.select()

If the browser supports a Selection object or TextRange objects, you may then be able to access the selected text using JavaScript. Of course in a form object, the text of the whole object can also be accessed, but this may not be what was selected because the user may select all or part of a page and that selection may span several form elements or only part of a form element. See also:

Input.select()

TextCell.size (Property) The number of characters that have been typed into the text cell. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

String primitive

JavaScript syntax:

IE

myTextCell.size

This is an approximate measure at best. You cannot be sure how wide this box really needs to be when using a proportionally spaced font in it. The browser will size the box close to an optimal size to cope with the specified number of characters.

Warnings: ❑

It can be quite distracting if the box size is too small to accommodate the maxLength number of characters. This can leave the user having to do some cumbersome select actions with the mouse or use arrow keys to reveal the hidden parts of the textual content of the box. See also:

2216

Input.size, Password.size

T – TextCell.type (Property)

TextCell.type (Property) The type of this Input object. Availability:

DOM level – 1 JavaScript – 1.1 JScript – 3.0 Internet Explorer – 4.0 Netscape – 3.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTextCell.type

The value of this property for a TextCell object must always be "text". This value is necessary to determine the type of form element because this object is really an instance of the Input class and not the TextCell class. There is actually no TextCell class. See also:

Input.type

Property attributes: ReadOnly.

TextCell.value (Property) The text string that has been entered into the text cell. Availability:

DOM level – 1 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Opera – 3.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTextCell.value

This may be the same as the defaultValue if the user has not yet entered any text into the TextCell. See also:

Input.value, TEXTAREA.value

2217

JavaScript Programmer's Reference

textNode object (Object/DOM) A string of text represented as a node within the document hierarchy. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Inherits from:

CharacterData object

JavaScript syntax:

IE

myTextNode = myDocument.all.tags("TEXT")[anIndex] myTextNode = myDocument.createTextNode(someData)

Argument list:

someData

Textual content for the text node

anIndex

A selector within a collection of text nodes

Object properties:

data, length

Object methods:

splitText()

The MSIE browser models the document as a collection of nodes. Clearly, an HTML tag corresponds to an object. However, what isn't so obvious is that the text in between HTML tags is collected together and represented by a textNode object. These textNodes are generally accessible as child objects belonging to an object instantiated by an HTML tag. For example: AAA

BBB

CCC can be accessed as follows: The

tags are objects which are members of the document.getElementsByTagName("P") collection. The text "BBB" is referenced through the firstChild property of the P object instantiated by the first

tag. The text "CCC" is a textNode object referenced via the firstChild property of the second

tag. The DOM level 3 specification is expected to add the following method to the textNode object: ❑

isWhitespaceInElementContent() Attribute.nodeName, Document.createTextNode()

See also:

Property

JavaScript

JScript

N

IE

Opera

DOM

Notes

data

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

length

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

ReadOnly

2218

T – textNode.data (Property)

Method

JavaScript

JScript

N

IE

Opera

DOM

Notes

splitText()

1.5 +

5.0 +

6.0 +

5.0 +

-

1+

-

Inheritance chain: CharacterData object, Node object

textNode.data (Property) The data associated with a text node within the document. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

String primitive

JavaScript syntax:

-

myTextNode.data

A text node is that textual content in between objects that represent HTML tags. If the HTML tags are bricks in a wall, then the text is the mortar joining them all together. The text nodes could also be called interstitial nodes because they exist in the cracks between HTML Elements.

textNode.length (Property) The length of the text in a textNode object. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

Number primitive

JavaScript syntax:

-

myTextNode.length

The text enclosed in a text node can be measured for length by this property. However it is still stored as a string value in the data property and you should not assume that it is an array simply because it has a length property.

Property attributes: ReadOnly.

2219

JavaScript Programmer's Reference

textNode.splitText() (Method) A means of splitting the text in a text node into two so that HTML can be placed in between them. Availability:

DOM level – 1 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

Property/method value type:

textNode object

JavaScript syntax:

-

myTextNode.splitText(anOffset)

Argument list:

anOffset

The location within the text data to split the text at

This is functionally similar to splitting a String object. The character index, using a zero-based counting scheme where the split is to occur, should be passed as an argument. The method returns the text to the right of the split. The receiving object is truncated at the split point. You can then append some HTML to the receiving object and then append the text object that was returned by the method.

TextRange object (Object/JScript) An object that represents part of the text stream of an HTML document. Availability:

JScript – 3.0 Internet Explorer – 4.0

Inherits from:

Element object

JavaScript syntax:

IE

Object properties:

boundingHeight, boundingLeft, boundingTop, boundingWidth, htmlText, text

Object methods:

collapse(), compareEndPoints(), duplicate(), execCommand(), expand(), findText(), getBookmark(), getBoundingClientRect(), getClientRects(), inRange(), isEqual(), move(), moveEnd(), moveStart(), moveToBookmark(), moveToElementText(), moveToPoint(), parentElement(), pasteHTML(), queryCommandEnabled(), queryCommandIndeterm(), queryCommandState(), queryCommandSupported(), queryCommandText(), queryCommandValue(), select(), setEndPoint()

myTextRange = myElement.createTextRange()

The main purpose of a TextRange object is to encapsulate that part of the document text that depends on the user having used the mouse to select a portion of text. A TextRange object can also encapsulate an insertion point in the text of a document.

2220

T – TextRange object (Object/JScript) An insertion point is encapsulated by creating a TextRange object that is of zero length. A new TextRange object is instantiated with the createTextRange() method which can be applied to the following object types which can contain selectable text: ❑

BODY



TextCell



TEXTAREA

The TextCell and TEXTAREA objects are members of the Form Element category, sometimes called Input Elements. When you have created a TextRange object, you can then manipulate its properties to select just that portion of text in the document that you want. Once you have marked the text you want within the start and end points, you can replace the content of the TextRange with the pasteHTML() method to operate on the text in the document. However, there may be limitations on when and how you can do this depending on the extent of the TextRange object's boundaries.

Warnings: ❑

There are platform limitations to the TextRange object that mean it is only functional on the Windows platform within MSIE. This limits the audience for your ingenuity in using it, but within a captive environment, this capability can still be useful. See also:

BODY.createTextRange(), Button object, BUTTON object, Element.isTextEdit, Element.parentTextEdit, Input.createTextRange(), Selection object, selection.createRange(), TEXTAREA object, TextCell object

Property

JavaScript

JScript

N

IE

Opera

Notes

boundingHeight

-

3.0 +

-

4.0 +

-

ReadOnly

boundingLeft

-

3.0 +

-

4.0 +

-

ReadOnly

boundingTop

-

3.0 +

-

4.0 +

-

ReadOnly

boundingWidth

-

3.0 +

-

4.0 +

-

ReadOnly

htmlText

-

3.0 +

-

4.0 +

-

ReadOnly

text

-

3.0 +

-

4.0 +

-

-

Method

JavaScript

JScript

N

IE

Opera

Notes

collapse()

-

3.0 +

-

4.0 +

-

-

compareEndPoints()

-

3.0 +

-

4.0 +

-

-

duplicate()

-

3.0 +

-

4.0 +

-

-

execCommand()

-

3.0 +

-

4.0 +

-

-

Table continued on following page

2221

JavaScript Programmer's Reference

Method

JavaScript

JScript

N

IE

Opera

Notes

expand() findText() getBookmark() getBoundingClientRect() getClientRects() inRange() isEqual() move() moveEnd() moveStart() moveToBookmark() moveToElementText() moveToPoint() parentElement() pasteHTML() queryCommandEnabled() queryCommandIndeterm() queryCommandState() queryCommandSupported() queryCommandText() queryCommandValue() select() setEndPoint()

-

3.0 + 3.0 + 3.0 + 5.0 + 5.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 + 3.0 +

-

4.0 + 4.0 + 4.0 + 5.0 + 5.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 + 4.0 +

-

Warning Warning -

Inheritance chain: Element object, Node object

TextRange.boundingHeight (Property) The height of the extent rectangle around selected text on the page. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTextRange.boundingHeight

TextRange objects use the start and end points to map into the physical display of the text on the screen. Although it may not be visible, the text range nevertheless corresponds to a spatial extent rectangle that can be described using pixel coordinates. The value of this property is the height of the extent rectangle that currently encloses the text encapsulated by the TextRange object. See also:

2222

TextRange.boundingWidth

T – TextRange.boundingLeft (Property)

Property attributes: ReadOnly.

TextRange.boundingLeft (Property) The left edge of a selected text on the page. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTextRange.boundingLeft

TextRange objects use their start and end points to map into the physical display of the text on the screen. Although it may not be visible, the text range nevertheless corresponds to a spatial extent rectangle that can be described using pixel coordinates. This property's value is the X coordinate of the left edge of the extent rectangle that currently encloses the text encapsulated by the TextRange object.

Property attributes: ReadOnly.

TextRange.boundingTop (Property) The top edge of a selected text on the page. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTextRange.boundingTop

TextRange objects use their start and end points to map into the physical display of the text on the screen. Although it may not be visible, the text range nevertheless corresponds to a spatial extent rectangle that can be described using pixel coordinates. This property's value is the Y coordinate of the top edge of the extent rectangle that currently encloses the text encapsulated by the TextRange object.

Property attributes: ReadOnly.

2223

JavaScript Programmer's Reference

TextRange.boundingWidth (Property) The width of a selected text on the page. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Number primitive

JavaScript syntax:

IE

myTextRange.boundingWidth

TextRange objects use their start and end points to map into the physical display of the text on the screen. Although it may not be visible, the text range nevertheless corresponds to a spatial extent rectangle that can be described using pixel coordinates. The value of this property is the width of the extent rectangle that currently encloses the text encapsulated by the TextRange object. See also:

TextRange.boundingHeight

Property attributes: ReadOnly.

TextRange.collapse() (Method) A method that shrinks a text range to an insertion point. Availability: JavaScript syntax: Argument list:

JScript – 3.0 Internet Explorer – 4.0 myTextRange.collapse() IE IE

myTextRange.collapse(aFlag)

aFlag

A Boolean value to indicate which end of the text range should become the insertion point

You can call this method to shrink the TextRange to an insertion point either at the start or end of the text range. If no value is passed as an argument, then the insertion point is taken from the start of the text range. A Boolean true value also uses the startpoint as the new insertion point. A Boolean value of false selects the endpoint as the new insertion point.

2224

T – TextRange.compareEndPoints() (Method)

TextRange.compareEndPoints() (Method) Compare two TextRange objects. Availability: JavaScript syntax: Argument list:

JScript – 3.0 Internet Explorer – 4.0 myTextRange.compareEndPoints IE (anOperator, aTextRange) anOperator A selector for the kind of comparison aTextRange

A reference to another TextRange object

The typical means of comparing two objects is to pass a reference to one object as an argument to a method invoked on the other. This method performs such a comparison. The first keyword is an operator to indicate the kind of comparison to be carried out. The second argument is a reference to the second TextRange object that it is to be compared with. The following keywords can be passed in the first argument as string values: ❑

StartToEnd



StartToStart



EndToStart



EndToEnd

The values returned by this method are -1, 0 or 1. These indicate whether the first value is before, coincident with or after the second value. The operator dictates which values are to be tested. See also:

TextRange.isEqual(), TextRange.setEndPoint()

TextRange.duplicate() (Method) Duplicate a TextRange object. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

TextRange object

JavaScript syntax:

IE

myTextRange.duplicate()

This is a deep copy of a TextRange object. Simply assigning the value of one variable copies only the reference to the same object. You need to call this method to create a new object whose properties are set to the same values as its parent.

2225

JavaScript Programmer's Reference

TextRange.execCommand() (Method) Part of an MSIE special document command handling mechanism. Execute a command across the text range. Availability:

JScript – 3.0 Internet Explorer – 4.0

Property/method value type:

Boolean primitive

JavaScript syntax:

IE

myTextRange.execCommand(aCommand)

IE

myTextRange.execCommand(aCommand, aUIFlag) myTextRange.execCommand(aCommand, aUIFlag, aParameter)

IE Argument list:

aCommand

An MSIE command to execute

aParameter

Parameter value to the command

aUIFlag

Display or inhibit UI appearance

The MSIE browser supports a special command handling interface that hooks through the browser's user interface. It allows you to automate user actions in a way that other browsers and non-Windows platform users cannot take advantage of. It is another example of the Microsoft Embrace, Enhance and Eliminate approach to dominating the browser marketplace. Although this is a method that can be applied to a document object, many of the commands that are executed through this mechanism will require that a TextRange object is created and available first. The result returned by this method is a Boolean true if the action succeeded and a Boolean false if it failed in some way. The flag parameter provides a way to suppress any user interface changes that may appear as a result of executing the command. Name

Description

2D-Position

Absolutely positioned elements can be moved by dragging.

AbsolutePosition

Sets an element's position property to "absolute".

BackColor

The background color for the current selection is set to the color value passed in the parameter argument.

Bold

The selected text has and tags placed at either end.

Copy

The TextRange is copied to the clipboard.

CreateBookmark

Carries out modifications to an existing tag or creates one, then adds the item to the bookmarks list. The parameter provides the NAME value. The tag is removed if there is no parameter.

CreateLink

Wraps an tag around the selected text. The parameter contains the URL value for the HREF.

Cut

Performs a cut to clipboard.

Delete

The text range is deleted. This is not the same as a Cut command. Table continued on following page

2226

T – TextRange.execCommand() (Method)

Name

Description

FontName

Wraps tags round the selection. The required font face is passed in the parameter.

FontSize

Wraps tags round the selection and defines the font's size from the parameter value.

ForeColor

Redefines the foreground text color for the selection taking the color value from the parameter.

FormatBlock

Wraps a tag round the TextRange.

Indent

The TextRange is indented.

InsertButton

A tag is placed at the current insertion point in the document. Its ID value is defined by the parameter.

InsertFieldset

A tag is inserted with the ID value being taken from the parameter.

InsertHorizontalRule

An tag is added at the current insertion point.

InsertIFrame

A new is inserted with the content URL being provided in the parameter.

InsertImage

Overwrites an image on the current selection.

InsertInputButton

An is added with its ID value coming from the parameter.

InsertInputCheckbox

An tag is added with its ID value coming from the parameter.

InsertInputFileUpload

An is added with its ID value coming from the parameter.

InsertInputHidden

An is added with its ID value coming from the parameter.

InsertInputImage

An is added with its ID value coming from the parameter.

InsertInputPassword

An is added with its ID value coming from the parameter.

InsertInputRadio

An is added with its ID value coming from the parameter. An is added with its ID value coming from the parameter. An is added with its ID value coming from the parameter. An is added with its ID value coming from the parameter. A new is added with the ID being taken from the parameter. A new is added with the ID being taken from the parameter. A new

is added with the ID being taken from the parameter. A new is added with the ID being taken from the parameter. A new is added with the ID being taken from the parameter. Table continued on following page

InsertInputReset InsertInputSubmit InsertInputText InsertMarquee InsertOrderedList InsertParagraph InsertSelectDropdown InsertSelectListbox

2227

JavaScript Programmer's Reference

Name

Description

InsertTextArea InsertUnorderedList Italic JustifyCenter JustifyFull JustifyLeft JustifyRight LiveResize

A new is added with the ID being taken from the parameter. A new

    is added with the ID being taken from the parameter. The TextRange is enclosed with tags. The TextRange is centered within its parent object. The TextRange is fully justified. The TextRange is left justified. The TextRange is right justified. Causes the MSHTML Editor to update an element's appearance continuously during a resizing or moving operation, rather than updating only at the completion of the move or resize. Allows for the selection of more than one site selectable element at a time when the user holds down the SHIFT or CTRL keys. The complement of the Indent command. The input-typing mode is set to overwrite if the parameter value is true and insert if it is false. The contents of the clipboard are pasted into the TextRange. If an image represents a video clip, then it starts playing. The document is reloaded. The complement of the FormatBlock command. Saves the current web page to a file. The entire document text is selected. The complement of the PlayImage command. The complement of the CreateBookmark command. Places tags around the TextRange. The complement of the CreateLink command. Unselects whatever was selected to create the TextRange. Many commands are now inappropriate until a new TextRange has been created.

    MultipleSelection Outdent OverWrite Paste PlayImage Refresh RemoveFormat SaveAs SelectAll StopImage UnBookmark Underline Unlink Unselect

    None of these commands provides any greatly significant functionality as far as dynamic HTML is concerned. A few of them allow you to manage the clipboard and bookmark lists. It is probably best to avoid using these commands and use the more usual ways of accessing the document internals. See also:

    2228

    Document.execCommand(), FileUpload.select(), TextRange.queryCommandEnabled(), TextRange.queryCommandIndeterm(), TextRange.queryCommandState(), TextRange.queryCommandSupported(), TextRange.queryCommandText(), TextRange.queryCommandValue()

    T – TextRange.expand() (Method)

    TextRange.expand() (Method) Expands a TextRange by a character, word, sentence or story. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.expand(aSelector)

    Argument list:

    aSelector

    Indicates what to expand the TextRange by

    This method has a single argument. The argument indicates what to look for when expanding the TextRange object. The end point is modified according to the rules determined by this keyword. The following keywords can be applied: ❑

    character



    word



    sentence



    textedit

    The character keyword causes the endpoint to be indexed onwards by a single character position. The word keyword looks for the next word break in the document text. It also moves the start point to he beginning of the word. The sentence keyword looks for the next full stop at the end of a sentence. It also looks onwards from this to move the start point to the beginning of the sentence. The textedit keyword restores the TextRange so it encapsulates only the original selection. This method returns a Boolean true if the range expansion succeeded and a Boolean false if it didn't. See also:

    TextRange.move()

    TextRange.findText() (Method) Defines a text range according to a search. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    TextRange object

    JavaScript syntax:

    IE

    myTextRange.findText(aString)

    Argument list:

    aString

    A string to find in the TextRange object

    This is a case-insensitive search for a matching text. If the text is located, then the start and end points of the TextRange object are adjusted to encapsulate the found text chunk.

    2229

    JavaScript Programmer's Reference

    The TextRange needs to be collapsed for this to work. It could be collapsed and made to point at the start of the document if you want to search the whole text, otherwise the search commences at the current insertion point. This method returns a Boolean true if it found a match and a Boolean false if it didn't.

    TextRange.getBookmark() (Method) Bookmarks a position in a text range. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    TextRange bookmark

    JavaScript syntax:

    IE

    myTextRange.getBookmmark()

    These are not user bookmarks that are stored in the favorites menu but are special bookmarks for remembering access points in TextRange objects. This method generates a special value that can be stored in a variable and can later be passed to the moveToBookmark() method to restore the start and end points of the TextRange to the current values. It's a simple way to store and restore the settings of a TextRange. See also:

    TextRange.moveToBookmark()

    TextRange.getBoundingClientRect() (Method) A method that returns a rectangle measured in pixels within the client display surface. Availability:

    JScript – 5.0 Internet Explorer – 5.0

    Property/method value type:

    Rect object

    JavaScript syntax:

    IE

    myTextRange.getBoundingClientRect()

    This method evaluates the current start and end points of the text range and works out the pixel locations of a bounding rectangle in the display screen. These are then used to instantiate a textRectangle object which is returned with the extent rectangle of the TextRange object as its values. A TextRange may describe several discontinuous blocks of text. Each one of these would be bounded by a separate client rectangle. This extent rectangle bounds the entire set. See also:

    2230

    Rect object, textRectangle object

    T – TextRange.getClientRects() (Method)

    TextRange.getClientRects() (Method) A collection of textRectangle objects within the client display surface. Availability:

    JScript – 5.0 Internet Explorer – 5.0

    Property/method value type:

    Collection object

    JavaScript syntax:

    IE

    myTextRange.getClientRects()

    A TextRange may describe several discontinuous blocks of text. Each one of these would be bounded by a separate client rectangle. This method evaluates the current start and end points of the text range and works out the pixel locations of a bounding rectangle in the display screen for each of the different text areas. These are then used to instantiate a textRectangle object which is added to a collection. The collection of individual client textRectangle objects is then returned to the caller. See also:

    textRectangle object

    TextRange.htmlText (Property) Returns a text range as HTML source. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTextRange.htmlText

    This is somewhat similar to the innerHTML of an Element object. In this case the start and end points of the TextRange are taken as the delimiting boundaries. The HTML contained within those boundaries can be returned to your script when the property is read. Because this property is read-only, you will need to use the pasteHTML() method to replace the HTML bounded by a TextRange object. See also:

    TextRange.pasteHTML(), TextRange.text

    Property attributes: ReadOnly.

    2231

    JavaScript Programmer's Reference

    TextRange.inRange() (Method) Tests for one text range within another. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextRange.inRange(aTextRange)

    Argument list:

    aTextRange

    Another TextRange to test against

    Given that you have two distinctly separate TextRange objects, you can test whether one is contained within the other by passing it as an argument to this method.

    TextRange.isEqual() (Method) Tests two text ranges for equality. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextRange.isEqual(aTextRange)

    Argument list:

    aTextRange

    Another TextRange to compare against

    Given that you have two distinctly separate TextRange objects, you can test whether they are both equivalent to one another by passing one as an argument to this method being called on the other. You may accomplish the same thing less conveniently with the compareEndPoints() method. See also:

    TextRange.compareEndPoints()

    TextRange.move() (Method) Relocates the insertion point of a TextRange. Availability: JavaScript syntax: Argument list:

    JScript – 3.0 Internet Explorer – 4.0 myTextRange.move(aSelector) IE IE aCount

    myTextRange.move(aSelector, aCount)

    aSelector

    A rule selector

    Indicates how many times to iterate

    The TextRange is collapsed to an insertion point at the end of the current bounded range. Then the keyword determines how the insertion point is indexed onwards or backwards.

    2232

    T – TextRange.moveEnd() (Method)

    This method has two arguments. The first argument indicates what to look for when moving the TextRange object. The second indicates how many times to apply that location search. A negative value indicates a backwards search. The insertion point is modified according to the rules determined by this keyword. If the second argument is omitted, it is assumed to be the value 1. The following keywords can be applied: ❑

    character



    word



    sentence



    textedit

    The character keyword causes the insertion point to be indexed onwards by a single character position. The word keyword looks for the next word break in the document text. The sentence keyword looks for the next full stop at the end of a sentence. The textedit keyword moves the insertion point either to the beginning or end of the original selection. This method returns an integer describing how many times it was able to move the insertion pointer. See also:

    TextRange.expand()

    TextRange.moveEnd() (Method) Relocates the end point of a TextRange. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.moveEnd(aSelector)

    IE

    myTextRange.moveEnd(aSelector, aCount)

    aCount

    Indicates how many times to iterate

    aSelector

    A rule selector

    Argument list:

    This works in almost the same way as the move() method but instead of collapsing the TextRange first, it just operates on the end point of the current text range. Then the keyword determines how the end point is indexed onwards or backwards. This method has two arguments. The first argument indicates what to look for when adjusting the TextRange object. The second indicates how many times to apply that location search. A negative value indicates a backwards search. The end point is modified according to the rules determined by this keyword. If the second argument is omitted, it is assumed to be the value 1. The following keywords can be applied:

    2233

    JavaScript Programmer's Reference



    character



    word



    sentence



    textedit

    The character keyword causes the endpoint to be indexed onwards by a single character position. The word keyword looks for the next word break in the document text. The sentence keyword looks for the next full stop at the end of a sentence. The textedit keyword moves the end point either to the beginning or end of the original selection. This method returns an integer describing how many times it was able to move the end point.

    Warnings: ❑

    Be careful that the start and end points do not get crossed over. It is possible that the internal logic of the browser would cope with this and fix things up, but it is a likely area where the browser may be expected to fail.

    TextRange.moveStart() (Method) Relocates the start point of a TextRange. Availability: JavaScript syntax:

    Argument list:

    JScript – 3.0 Internet Explorer – 4.0 myTextRange.moveStart(aSelector) IE IE

    myTextRange.moveStart(aSelector, aCount)

    aCount

    Indicates how many times to iterate

    aSelector

    A rule selector

    This works in almost the same way as the move() method but instead of collapsing the TextRange first, it just operates on the start point of the current text range. Then the keyword determines how the start point is indexed onwards or backwards. This method has two arguments. The first argument indicates what to look for when adjusting the TextRange object. The second indicates how many times to apply that location search. A negative value indicates a backwards search. The start point is modified according to the rules determined by this keyword. If the second argument is omitted, it is assumed to be the value 1. The following keywords can be applied: ❑

    character



    word



    sentence



    textedit

    2234

    T – TextRange.moveToBookmark() (Method) The character keyword causes the startpoint to be indexed onwards by a single character position. The word keyword looks for the next word break in the document text. The sentence keyword looks for the next full stop at the end of a sentence. The textedit keyword moves the start point either to the beginning or end of the original selection. This method returns an integer describing how many times it was able to move the start point.

    Warnings: ❑

    Be careful that the start and end points do not get crossed over. It is possible that the internal logic of the browser would cope with this and fix things up, but it is a likely area where the browser may be expected to fail.

    TextRange.moveToBookmark() (Method) Restores a bookmarked TextRange. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.moveToBookmark(aBookmark)

    Argument list:

    aBookmark

    A bookmark obtained from a getBookmark() method call

    This is the complement of the getBookmark() method. It takes the result of the getBookmark() method that would have been stored in a variable. The TextRange start and end points are then reset to the value that was originally defined when the bookmark was recorded. The Boolean value true is returned if the bookmarked locations could be restored and a Boolean false value if they couldn't. It really depends on what has happened since the bookmark was captured as to whether it can realistically be restored or not. See also:

    TextRange.getBookmark()

    TextRange.moveToElementText() (Method) Expands the text range to encompass an HTML element. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.moveToElementText(anObject)

    Argument list:

    anObject

    A reference to an object in the document

    By passing an HTML Element object to this method, you can set the start and end points of the TextRange object to neatly bound the text of the HTML Element object.

    2235

    JavaScript Programmer's Reference

    TextRange.moveToPoint() (Method) Expand the text range to include an x, y location. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.moveToPoint(anX, aY)

    anX

    An X coordinate value

    aY

    A Y coordinate value

    Argument list:

    The TextRange can be set to create an insertion point in the text that corresponds with the X-Y coordinate point of an onscreen location. This is smart stuff indeed because it would be very difficult to compute the text flow and correlate it with screen coordinates. The result is that the TextRange is set to an insertion point.

    TextRange.parentElement() (Method) A reference to an object that is the next outermost item in the document hierarchy. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Element object

    JavaScript syntax:

    IE

    myTextRange.parentElement()

    Having established that a TextRange may correspond to some block of text within the document, this returns a reference to an HTML Element object that fully encloses the TextRange. For example, if a TextRange was set to bound a couple of Input elements within a Form, this method might return the Form object because that is the next outermost logical object. Of course you could get a TABLE object if the form contained a table with the input elements inside it.

    TextRange.pasteHTML() (Method) Pastes HTML or plain text into the text range. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.pasteHTML(someHTML)

    Argument list:

    someHTML

    A string containing valid HTML

    Because the htmlText property is a read-only value, you will need to use this method to replace the HTML bounded by the TextRange or to insert HTML if the TextRange describes an insertion point. See also:

    2236

    TextRange.htmlText

    T – TextRange.queryCommandEnabled() (Method)

    TextRange.queryCommandEnabled() (Method) Part of an MSIE special document command handling mechanism. Indicates the disposition of the specified command. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextRange.queryCommandEnabled (aCommandName)

    Argument list:

    aCommandName

    An MSIE command name

    This method returns a Boolean value that indicates whether the named command is enabled. Many factors can affect the result of this command. It may depend on the ready state of the document or whether a selection is in force. Refer to the TextRange.execCommand() method for a list of the available commands. See also:

    Document object, Document.queryCommandEnabled(), TextRange.execCommand()

    TextRange.queryCommandIndeterm() (Method) Part of an MSIE special document command handling mechanism. Indicates whether the command is in an indeterminate state. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextRange.queryCommandIndeterm (aCommandName)

    Argument list:

    aCommandName

    An MSIE command name

    If the document is not fully loaded (you can check the readyState), or if a command might not be available due to some of its prerequisites not being set (such a selection creating a TextRange), this method will return a Boolean true value. If it returns a Boolean false, then the command may be available as determined by the enabled test. See also:

    Document object, Document.queryCommandIndeterm(), TextRange.execCommand()

    2237

    JavaScript Programmer's Reference

    TextRange.queryCommandState() (Method) Part of an MSIE special document command handling mechanism. Returns the current state of a command. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive or Null

    JavaScript syntax:

    IE

    myTextRange.queryCommandState (aCommandName)

    Argument list:

    aCommandName

    An MSIE command name

    This will return one of the following values: ❑

    Boolean true if the command has completed.



    Boolean false if it is still in progress.



    Null if the state cannot be determined. See also:

    Document object, Document.queryCommandState(), TextRange.execCommand()

    TextRange.queryCommandSupported() (Method) Part of an MSIE special document command handling mechanism. Checks to see if a command is supported. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextRange.queryCommandSupported (aCommandName)

    Argument list:

    aCommandName

    An MSIE command name

    Some commands are not supported by the TextRange object but may be supported by the document object. This method returns a Boolean true value if the command is supported by the TextRange object. See also:

    2238

    Document object, Document.queryCommandSupported(), TextRange.execCommand()

    T – TextRange.queryCommandText() (Method)

    TextRange.queryCommandText() (Method) Part of an MSIE special document command handling mechanism. Returns the string associated with a command. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTextRange.queryCommandText (aCommandName)

    Argument list:

    aCommandName

    An MSIE command name

    Some commands support the extraction of text from the document or TextRange. If the command does support the extraction of text, it will be returned by this method. See also:

    Document object, Document.queryCommandText(), TextRange.execCommand()

    TextRange.queryCommandValue() (Method) Part of an MSIE special document command handling mechanism. Returns the value of the command. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTextRange.queryCommandValue (aCommandName)

    Argument list:

    aCommandName

    An MSIE command name

    The value of a command depends on the command itself and what is selected. This method returns a value according to those criteria. See also:

    Document object, Document.queryCommandValue(), TextRange.execCommand()

    TextRange.select() (Method) Select the text range. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.select()

    2239

    JavaScript Programmer's Reference

    If the browser supports a Selection object or TextRange objects, you may then be able to access the selected text using JavaScript. Of course in a form object, the text of the whole object can also be accessed, but this may not be what was selected because the user may select all or part of a page, and that selection may span several form elements or only part of a form element. Unless you call this method, the bounded area of the TextRange object will not be visible to the user.

    TextRange.setEndPoint() (Method) Set the end point of a text range. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextRange.setEndPoint (anOperator, aTextRange)

    anOperator

    A selector for the kind of copy

    aTextRange

    A reference to another TextRange object

    Argument list:

    This method provides a way to copy start and end points between distinctly different TextRange objects. The first keyword is an operator to indicate the kind of copy to be carried out. The second argument is a reference to the second TextRange object that is to act as a source for the new values. Although this method is called setEndPoint(), it will allow both start and end points to be modified. The following keywords can be passed in the first argument as string values: ❑

    StartToEnd



    StartToStart



    EndToStart



    EndToEnd

    There are no values returned by this method. The indicated end points are simply copied from the source range to the target range. See also:

    TextRange.compareEndPoints()

    TextRange.text (Property) Extract the text of a text range. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    2240

    myTextRange.text

    T – textRectangle object (Object/JScript) This is somewhat similar to the innerText of an Element object. In this case the start and end points of the TextRange are taken as the delimiting boundaries. The text contained within those boundaries can be returned to your script when the property is read. If there are any HTML tags within the bounded extent of the TextRange, they will be filtered out so that the method yields pure text only values. Because this property is read-only, you will need to use the pasteHTML() method to replace the HTML bounded by a TextRange object. However, because there appears not to be a pasteText() method, you may need to do some complex reconstructive work if there was embedded HTML and you only requested the text. TextRange.htmlText

    See also:

    textRectangle object (Object/JScript) The extent rectangle that encloses a TextRange object.

    JavaScript syntax:

    JScript – 5.0 Internet Explorer – 5.0 myTextRectangle = IE myTextRange.getBoundingClientRect()

    Object properties:

    bottom, left, right, top

    Availability:

    This is a close relation to the rect object. This is a special case, used for describing rectangles on the screen which are the bounding extent rectangles for TextRange objects. You shouldn't try to modify the properties of this object directly. It's intended for you to read to establish where on the screen the TextRange is located. Clip object, Rect object, TextRange.getBoundingClientRect(), TextRange.getClientRects()

    See also:

    Property

    JavaScript

    JScript

    N

    IE

    Opera

    Notes

    bottom left right top

    -

    5.0 + 5.0 + 5.0 + 5.0 +

    -

    5.0 + 5.0 + 5.0 + 5.0 +

    -

    -

    textRectangle.bottom (Property) The bottom of a textRectangle. Availability:

    JScript – 5.0 Internet Explorer – 5.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    IE

    myTextRectangle.bottom

    2241

    JavaScript Programmer's Reference

    See also:

    Rect.bottom, textRectangle object

    textRectangle.left (Property) The left edge of a textRectangle. Availability:

    JScript – 5.0 Internet Explorer – 5.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    IE

    See also:

    Rect.left, textRectangle object

    myTextRectangle.left

    textRectangle.right (Property) The right edge of a text rectangle. Availability:

    JScript – 5.0 Internet Explorer – 5.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    IE

    See also:

    Rect.right, textRectangle object

    myTextRectangle.right

    textRectangle.top (Property) The top edge of a textRectangle. Availability:

    JScript – 5.0 Internet Explorer – 5.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    IE

    See also:

    Rect.top, textRectangle object

    2242

    myTextRectangle.top

    T – TextStream object (Object/JScript)

    TextStream object (Object/JScript) An object that represent an I/O text stream. Very useful in a server-side context. Availability: JavaScript syntax:

    Argument list:

    JScript – 2.0 Internet Explorer – 4.0 myTextStream = myFile.OpenAsTextStream() IE IE

    myTextStream = myFileSystem.OpenTextFile (aName, aMode, aFlag, aFormat)

    aName

    The name of the file to be created

    aFlag

    A flag indicating whether the file can be created if necessary

    aMode

    An access mode for the file

    aFormat

    A format control for the file

    Object properties:

    AtEndOfLine, AtEndOfStream, Column, Line

    Object methods:

    Close(), Read(), ReadAll(), ReadLine(), Skip(), SkipLine(), Write(), WriteBlankLines(), WriteLine()

    This object is a wrapper for a file when opened for I/O. With this object you can read and write to the file. Files can be opened via methods belonging to the File object or by requesting that the FileSystem object open a named file. Both techniques yield the same kind of TextStream object. See also:

    Active Server Pages, File.OpenAsTextStream(), FileSystem.OpenTextFile()

    Property

    JavaScript

    JScript

    N

    IE

    Opera

    Notes

    AtEndOfLine

    -

    2.0 +

    -

    4.0 +

    -

    -

    AtEndOfStream

    -

    2.0 +

    -

    4.0 +

    -

    -

    Column

    -

    2.0 +

    -

    4.0 +

    -

    -

    Line

    -

    2.0 +

    -

    4.0 +

    -

    -

    Method

    JavaScript

    JScript

    N

    IE

    Opera

    Notes

    Close()

    -

    2.0 +

    -

    4.0 +

    -

    -

    Read()

    -

    2.0 +

    -

    4.0 +

    -

    -

    ReadAll()

    -

    2.0 +

    -

    4.0 +

    -

    -

    ReadLine()

    -

    2.0 +

    -

    4.0 +

    -

    -

    Skip()

    -

    2.0 +

    -

    4.0 +

    -

    -

    SkipLine()

    -

    2.0 +

    -

    4.0 +

    -

    -

    Write()

    -

    2.0 +

    -

    4.0 +

    -

    -

    WriteBlankLines()

    -

    2.0 +

    -

    4.0 +

    -

    -

    WriteLine()

    -

    2.0 +

    -

    4.0 +

    -

    -

    2243

    JavaScript Programmer's Reference

    TextStream.AtEndOfLine (Property) A Boolean value that indicates the status of the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextStream.AtEndOfLIne

    This property returns a value true if the file pointer is immediately preceding an end of line character.

    TextStream.AtEndOfStream (Property) A Boolean value that indicates the status of the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    IE

    myTextStream.AtEndOfStream

    This property returns the Boolean value true if the file pointer is at the end of the text stream.

    TextStream.Close() (Method) A method that closes a text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextStream.Close()

    The text stream is closed and any subsequent access will generate an error. You will need to reopen the text stream to gain access to it again.

    TextStream.Column (Property) The column number within the file. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    IE

    myTextStream.Column

    This property facilitates the use of fixed length record structured files via a stream. It yields the character column number within the current line.

    2244

    T – TextStream.Line (Property)

    TextStream.Line (Property) The line number within the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    IE

    myTextStream.Line

    The line number property is incremented for every newline character that is encountered within the file. This is effectively the record number within the file.

    TextStream.Read() (Method) A method that reads text from the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTextStream.Read(aCount)

    Argument list:

    aCount

    A count of characters to read

    This will read the specified number of characters from the file. Note that this may span a line break and is intended for reading fixed length records.

    TextStream.ReadAll() (Method) A method that reads the entire text stream in one go. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTextStream.ReadAll()

    The entire text stream is returned in a single read. Be careful if you are dealing with extraordinarily large files. You may get back more data than you expected.

    2245

    JavaScript Programmer's Reference

    TextStream.ReadLine() (Method) A method that reads a line from the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTextStream.ReadLine()

    This method will read the remainder of a line up to but not including the newline character.

    TextStream.Skip() (Method) A method that skips a specified number of characters through the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextStream.Skip(aCount)

    Argument list:

    aCount

    The number of characters to skip through the file

    Refer to: TextStream.Read()

    TextStream.SkipLine() (Method) A method that skips a line of the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    Refer to: TextStream.ReadLine()

    2246

    myTextStream.SkipLine()

    T – TextStream.Write() (Method)

    TextStream.Write() (Method) A method that writes to the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextStream.Write(aString)

    Argument list:

    aString

    Some text to write to the file

    This writes exactly (and only) the text passed in its string argument. See also:

    TextStream.WriteLine()

    TextStream.WriteBlankLines() (Method) A method that writes a specified number of blank lines to the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextStream.WriteBlankLines(aCoun t)

    Argument list:

    aCount

    The number of blank lines to write to the file

    This writes just the newline characters. The count value specifies just how many. See also:

    TextStream.WriteLine()

    TextStream.WriteLine() (Method) A method that writes a line to the text stream. Availability:

    JScript – 2.0 Internet Explorer – 4.0

    JavaScript syntax:

    IE

    myTextStream.WriteLine()

    IE

    myTextStream.WriteLine(aString)

    aString

    A string to be written to the file

    Argument list:

    This is similar to the Write() method except that it automatically places a newline character after the string that has been written. In addition, the string value is optional in which case this is functionally identical to calling WriteBlankLines(1). See also:

    TextStream.Write(), TextStream.WriteBlankLines()

    2247

    JavaScript Programmer's Reference

    TFOOT object (Object/HTML) An object that encapsulates a tag within a block. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Inherits from:

    Element object

    JavaScript syntax:

    IE

    myTFOOT = myDocument.all.anElementID

    IE

    myTFOOT = myDocument.all.tags("TFOOT")[anIndex] myTFOOT = myDocument.all[aName]

    IE HTML syntax: Argument list:

    myTFOOT = myDocument.getElementById(anElementID) myTFOOT = myDocument.getElementsByName(aName)[anIndex] myTFOOT = myDocument.getElementsByTagName ("TFOOT")[anIndex]

    ... anIndex

    A reference to an element in a collection

    aName

    An associative array reference

    anElementID

    The ID value of an Element object

    Object properties:

    align, bgColor, ch, chOff, vAlign

    Object methods:

    deleteRow(), insertRow()

    Event handlers:

    onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

    Collections:

    rows[]

    A table must contain one and only one TFOOT object. If you don't create one automatically, the TABLE object instantiates one for you but it would be empty. The TFOOT object is instantiated by a HTML tag. This is a means of marking off a section at the bottom of the table so that the rows can be grouped together and operated on separately to the table body. The DOM level 1 standard calls for the implementation of a TableSectionElement object which includes both TFOOT and THEAD in its capabilities.

    Warnings: ❑

    Some earlier versions of MSIE for Macintosh have very limited capabilities implemented for this object. You cannot access any of the HTML or text contained in the object, nor the rows collection.

    2248

    T – TFOOT object (Object/HTML)

    See also:

    Element object, TABLE object, TABLE.createTFoot(), TABLE.deleteTFoot(), TABLE.rules, TABLE.tFoot, THEAD object, TR object

    Property

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    align

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    bgColor

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    ch

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    chOff

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    vAlign

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    Method

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    deleteRow()

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    insertRow()

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    Event name

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    onClick

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onDblClick

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onDragStart

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onFilterChange

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onHelp

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    Warning

    onKeyDown

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onKeyPress

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onKeyUp

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseDown

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseMove

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    -

    4.0 +

    Warning

    onMouseOut

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseOver

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseUp

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onSelectStart

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    Inheritance chain: Element object, Node object

    2249

    JavaScript Programmer's Reference

    TFOOT.align (Property) The kind of horizontal alignment applied to items within the block of a table. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTFOOT.align

    The horizontal alignment of the TFOOT object with respect to its containing parent object is defined in this property. The available set of alignment specifiers are: ❑

    center



    left



    right



    char



    justify See also:

    TABLE.align, TBODY.align, TD.align, TH.align, THEAD.align, TR.align

    TFOOT.bgColor (Property) The background color for items in the block. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTFOOT.bgColor

    The background can be colored independently of whether an image is loaded into the background of an object. In fact it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:

    2250

    Color names, Color value, THEAD.bgColor

    T – TFOOT.ch (Property)

    TFOOT.ch (Property) The character used for alignment of columns within the table. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    myTFOOT.ch

    TFOOT.chOff (Property) The offset of character alignments within a column. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    myTFOOT.chOff

    TFOOT.deleteRow() (Method) In a multiple row footer, you can delete a particular row with this method. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    JavaScript syntax:

    -

    myTFOOT.deleteRow(anIndex)

    Argument list:

    anIndex

    The row to delete

    See also:

    THEAD.deleteRow()

    2251

    JavaScript Programmer's Reference

    TFOOT.insertRow() (Method) You can insert additional rows into a table footer with this method. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    TR object

    JavaScript syntax:

    -

    myTFOOT.insertRow(anIndex)

    Argument list:

    anIndex

    The row at which to place the new inserted TR object

    See also:

    THEAD.insertRow()

    TFOOT.rows[] (Collection) A collection of rows within a block belonging to a table. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    Collection object

    JavaScript syntax:

    -

    myTFOOT.rows

    This is not the same as the rows collection returned from a TABLE object. That is because the rows[] collection belonging to a TFOOT object can only list those TR objects that are contained within the tags. See also:

    Property attributes: ReadOnly.

    2252

    Collection object, TABLE.cells[], TABLE.cols, TABLE.rows[], TBODY.rows[], THEAD.rows[], TR.rowIndex

    T – TFOOT.vAlign (Property)

    TFOOT.vAlign (Property) The vertical alignment applied to items within the block of a table. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTFOOT.vAlign

    The vertical alignment of the content within the table cells can be controlled across an entire TFOOT extent with this property. The following keywords can be assigned to it: ❑

    baseline



    bottom



    middle



    top

    These may be also available on some implementations: ❑

    absbottom



    absmiddle



    baseline



    texttop See also:

    TBODY.vAlign, TD.vAlign, TH.vAlign, THEAD.vAlign, TR.vAlign

    TH object (Object/HTML) An object that encapsulates a anIndex

    A reference to an element in a collection

    aName

    An associative array reference

    anElementID

    The ID value of an Element object

    abbr, align, axis, background, bgColor, borderColor, borderColorDark, borderColorLight, cellIndex, ch, chOff, colSpan, headers, height, noWrap, rowSpan, scope, vAlign, width onAfterUpdate, onBeforeUnload, onBlur, onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onResize, onRowEnter, onRowExit, onSelectStart

    This object is instantiated by a row. This is effectively the horizontal column coordinate of a table header cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    -

    myTH.cellIndex

    You can access cells by means of the rows[] and cells[] collections belonging to the TABLE and TR objects respectively. This property provides the horizontal coordinate to use in the TR.cells[] collection to access the object describing this table cell. See also:

    TD.cellIndex

    Property attributes: ReadOnly.

    2259

    JavaScript Programmer's Reference

    TH.ch (Property) The alignment character for cells in a column arrangement. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    myTH.ch

    HTML 4.0 provides for text to be arranged in neat columns within table cells without the need to create additional tables within tables. This method of alignment is selected by setting the ALIGN="CHAR" HTML tag attribute. The CHAR HTML tag attribute is reflected in this property and is active when the CHAROFF HTML tag attribute is present. See also:

    COL.ch, COLGROUP.ch, TD.ch, THEAD.ch, TR.ch

    TH.chOff (Property) The offset of a column alignment character. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    myTH.chOff

    The CHAR alignment style requires that an alignment character be specified with the ch property and that an offset measured in pixels be defined as its value. The offset value can be defined with the CHAROFF HTML tag attribute. The remainder of the string is offset by this distance from the alignment character. See also:

    2260

    COL.chOff, COLGROUP.chOff, TD.chOff, THEAD.chOff, TR.chOff

    T – TH.colSpan (Property)

    TH.colSpan (Property) The number of columns that a header cell spans. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    -

    myTH.colSpan

    This corresponds to the COLSPAN attribute within a
    table header cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Inherits from:

    Element object

    2253

    JavaScript Programmer's Reference

    JavaScript syntax:

    HTML syntax: Argument list:

    Object properties:

    Event handlers:

    IE

    myTH = myDocument.all.anElementID

    IE

    myTH = myDocument.all.tags("TH")[anIndex]

    IE

    myTH = myDocument.all[aName]

    -

    myTH = myDocument.getElementById(anElementID)

    -

    myTH = myDocument.getElementsByName(aName)[anIndex]

    -

    myTH = myDocument.getElementsByTagName("TH")[anIndex]

    ... tag that encloses the content of a single data cell. This cell is formatted differently to a TD cell because a TH cell is considered to be a table header cell whereas a TD cell is a table data cell. Some of the property values in this object may be inherited from parent objects such as TABLE, TR and TBODY. See also:

    Element object, TABLE object, TD object

    Property

    JavaScript

    abbr align axis background

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    1.5 +

    -

    1.5 +

    3.0 +

    6.0 +

    -

    -

    1+

    -

    -

    6.0 +

    4.0 +

    -

    1+

    -

    -

    1.5 +

    -

    -

    3.0 +

    6.0 +

    -

    -

    1+

    -

    -

    -

    4.0 +

    -

    -

    -

    bgColor

    -

    1.5 +

    borderColor

    -

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    borderColorDark

    -

    borderColorLight

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    cellIndex

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    ReadOnly

    ch

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    chOff

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    colSpan

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    Warning

    Table continued on following page

    2254

    T – TH object (Object/HTML)

    Property

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    headers height

    1.5 +

    -

    1.5 +

    3.0 +

    6.0 +

    -

    -

    1+

    -

    -

    6.0 +

    4.0 +

    -

    1+

    -

    -

    noWrap

    1.5 +

    rowSpan

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    Warning

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    scope vAlign

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    width

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    Event name

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    onAfterUpdate

    -

    4.0 +

    -

    -

    -

    -

    -

    3.0 +

    onBeforeUnload

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onBlur

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    -

    Warning

    onClick

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onDblClick

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onDragStart

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onFilterChange

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onHelp

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    Warning

    onKeyDown

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onKeyPress

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onKeyUp

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseDown

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseMove

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    -

    4.0 +

    Warning

    onMouseOut

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseOver

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseUp

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onResize

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    -

    -

    Warning

    onRowEnter

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onRowExit

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onSelectStart

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    Inheritance chain: Element object, Node object

    2255

    JavaScript Programmer's Reference

    TH.abbr (Property) An abbreviation value to be used for header cells in the column where the data cell resides. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    See also:

    TD.abbr

    myTH.abbr

    TH.align (Property) The alignment of content within a
    table cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTH.align

    The alignment of the TH object with respect to its containing parent object is defined in this property. The available set of alignment specifiers are: ❑

    center



    left



    right



    char



    justify See also:

    2256

    TABLE.align, TBODY.align, TD.align, TFOOT.align, THEAD.align, TR.align

    T – TH.axis (Property)

    TH.axis (Property) The names group of related header cells. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    See also:

    TD.axis

    myTH.axis

    TH.background (Property) A URL for an image to load as the background for a table header cell. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTH.background

    If a background image is available, then its URL is contained in this property. Changing the value in this property will replace the background with a new one. However there may be a perceptible delay while the new image is fetched from the web server. See also:

    TD.background

    TH.bgColor (Property) The background color for a table header cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTH.bgColor

    2257

    JavaScript Programmer's Reference

    The background can be colored independently of whether an image is loaded into the background of an object. In fact it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:

    Color names, Color value, TD.bgColor

    TH.borderColor (Property) The border color around a table header cell. Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTH.borderColor

    You can use this property to determine the color of a border surrounding a table header cell. Note that there are additional properties to determine the highlights and lowlights of the table header cell border coloring. See also:

    TD.borderColor

    TH.borderColorDark (Property) The color value of the shadowed edge of the table cell border (assuming the table is lit from the top left). Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTH.borderColorDark

    Table header cell borders are presented as having an engraved appearance. This means you may need to control the highlights and lowlights. This property defines the color of the shadowed part of the table header cell border. See also:

    2258

    TD.borderColorDark

    T – TH.borderColorLight (Property)

    TH.borderColorLight (Property) The color value of the highlighted edge of the table cell border (assuming the table is lit from the top left). Availability:

    JScript – 3.0 Internet Explorer – 4.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    IE

    myTH.borderColorLight

    Table header cell borders are presented as having an engraved appearance. This means you may need to control the highlights and lowlights. This property defines the color of the highlighted part of the table header cell border. See also:

    TD.borderColorLight

    TH.cellIndex (Property) A zero-based integer number that indicates the position of a
    cell within a
    HTML tag for a table header cell description. It defines how many table columns this column is to span.

    Warnings: ❑

    Note that this may affect the value of the cellIndex property for subsequent cells within the same row. See also:

    COL.span, COLGROUP.span, style.columnSpan, TD.colSpan

    TH.headers (Property) A list of ID attribute values for header cells. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    See also:

    TD.headers

    myTH.headers

    2261

    JavaScript Programmer's Reference

    TH.height (Property) The height in pixels of the table header cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTH.height

    The table header cell space is defined by an extent rectangle that surrounds the space occupied by it on the screen. An extent rectangle is that smallest rectangle that completely encloses the item. This property specifies the height of that extent rectangle. See also:

    TD.height

    TH.noWrap (Property) Controls whether text in the table header cell is allowed to wrap. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    Boolean primitive

    JavaScript syntax:

    -

    myTH.noWrap

    This is a Boolean value that controls whether the textual content is wrapped at the right hand window border or not. If the value false is assigned to this property, then words will wrap as the page is drawn. This is good and is the way you would expect a browser to behave. The text will flow according to the space available. If the value true is assigned to this property, the line of text will continue to the right until a
    or other block level tag is encountered. This will force the horizontal width of the page to be extremely large and the user will need to scroll furiously to be able to see the text and then scroll back again for the start of the next line.

    2262

    T – TH.rowSpan (Property)

    Warnings: ❑

    Only use this if you plan to place line breaks at frequent intervals yourself and really do need to control the line breaks manually. See also:

    TD.noWrap

    TH.rowSpan (Property) The number of rows that the table header will span. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    Number primitive

    JavaScript syntax:

    -

    myTH.rowSpan

    This is used when you want to create complex tables. This technique may be an alternative to nesting a table. That is always good because sometimes nested tables can become very unwieldy. See also:

    style.rowSpan, TD.rowSpan

    TH.scope (Property) The scope covered by header cells. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    See also:

    TD.scope

    myTH.scope

    2263

    JavaScript Programmer's Reference

    TH.vAlign (Property) The vertical alignment of content within the table header cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTH.vAlign

    The vertical alignment of the content within the table cells can be controlled for a single table cell with this property. The following keywords can be assigned to it: ❑

    baseline



    bottom



    middle



    top

    These may be also available on some implementations: ❑

    absbottom



    absmiddle



    baseline



    texttop

    This value will override the setting for a row or TBODY extent. See also:

    TBODY.vAlign, TD.vAlign, TFOOT.vAlign, THEAD.vAlign, TR.vAlign

    TH.width (Property) The width in pixels of the table header cell. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    2264

    myTH.width

    T – THEAD object (Object/HTML)

    The table header cell space is defined by an extent rectangle that surrounds the space occupied by it on the screen. An extent rectangle is that smallest rectangle that completely encloses the item. This property specifies the width of that extent rectangle. See also:

    TD.width

    THEAD object (Object/HTML) An object that encapsulates a tag within a block. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Inherits from:

    Element object

    JavaScript syntax:

    IE

    myTHEAD = myDocument.all.anElementID

    IE

    myTHEAD = myDocument.all.tags("THEAD")[anIndex]

    IE

    myTHEAD = myDocument.all[aName]

    -

    myTHEAD = myDocument.getElementById(anElementID)

    -

    myTHEAD = myDocument.getElementsByName (aName)[anIndex] myTHEAD = myDocument.getElementsByTagName ("THEAD")[anIndex]

    HTML syntax: Argument list:

    ... anIndex

    A reference to an element in a collection

    aName

    An associative array reference

    anElementID

    The ID value of an Element object

    Object properties:

    align, bgColor, ch, chOff, vAlign

    Object methods:

    deleteRow(), insertRow()

    Event handlers:

    onClick, onDblClick, onDragStart, onFilterChange, onHelp, onKeyDown, onKeyPress, onKeyUp, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp, onSelectStart

    Collections:

    rows[]

    A table must contain one and only one THEAD object. If you don't create one automatically, the TABLE object instantiates one for you, but it will be empty. The THEAD object is instantiated by a HTML tag. This is a means of marking off a section at the top of the table so that the rows can be grouped together and operated on separately to the table body.

    2265

    JavaScript Programmer's Reference

    The DOM level 1 standard calls for the implementation of a TableSectionElement object which includes both TFOOT and THEAD in its capabilities. See also:

    Element object, TABLE object, TABLE.createTHead(), TABLE.deleteTHead(), TABLE.rules, TABLE.tHead, TFOOT object, TR object

    Property

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    align

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    bgColor

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    ch

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    chOff

    1.5 +

    -

    6.0 +

    -

    -

    1+

    -

    -

    vAlign

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    Method

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    deleteRow()

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    insertRow()

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    1+

    -

    -

    Event name

    JavaScript

    JScript

    N

    IE

    Opera

    DOM

    HTML

    Notes

    onClick

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onDblClick

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onDragStart

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onFilterChange

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    onHelp

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    Warning

    onKeyDown

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onKeyPress

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onKeyUp

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseDown

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseMove

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    -

    -

    4.0 +

    Warning

    onMouseOut

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseOver

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onMouseUp

    1.5 +

    3.0 +

    6.0 +

    4.0 +

    3.0 +

    -

    4.0 +

    Warning

    onSelectStart

    -

    3.0 +

    -

    4.0 +

    -

    -

    -

    -

    Inheritance chain: Element object, Node object

    2266

    T – THEAD.align (Property)

    THEAD.align (Property) The alignment of items within the block of a table. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTHEAD.align

    The alignment of the THEAD object with respect to its containing parent object is defined in this property. The following set of alignment specifiers are available: ❑

    center



    left



    right



    char



    justify See also:

    TABLE.align, TBODY.align, TD.align, TFOOT.align, TH.align, TR.align

    THEAD.bgColor (Property) The background color of items in the block of a table. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTHEAD.bgColor

    The background can be colored independently of whether an image is loaded into the background of an object. In fact it may be advisable to set the background color to something similar to the average color of the background image in case the image takes a long time to load or the browser is unable to display a background image. See also:

    Color names, Color value, TFOOT.bgColor

    2267

    JavaScript Programmer's Reference

    THEAD.ch (Property) The alignment character for cells in a column arrangement. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    myTHEAD.ch

    HTML 4.0 provides for text to be arranged in neat columns within table cells without the need to create additional tables within tables. This method of alignment is selected by setting the ALIGN="CHAR" HTML tag attribute. The CHAR HTML tag attribute is reflected in this property and is active when the CHAROFF HTML tag attribute is present. See also:

    COL.ch, COLGROUP.ch, TD.ch, TH.ch, TR.ch

    THEAD.chOff (Property) The offset of a column alignment character. Availability:

    DOM level – 1 JavaScript – 1.5 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    N

    myTHEAD.chOff

    The CHAR alignment style requires that an alignment character be specified with the ch property and that an offset measured in pixels be defined as its value. The offset value can be defined with the CHAROFF HTML tag attribute. The remainder of the string is offset by this distance from the alignment character. See also:

    2268

    COL.chOff, COLGROUP.chOff, TD.chOff, TH.chOff, TR.chOff

    T – THEAD.deleteRow() (Method)

    THEAD.deleteRow() (Method) In a multiple row footer, you can delete a particular row with this method. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    JavaScript syntax:

    -

    myTHEAD.deleteRow(anIndex)

    Argument list:

    anIndex

    The row to be deleted

    See also:

    TFOOT.deleteRow(), TR.deleteCell()

    THEAD.insertRow() (Method) You can insert additional rows into a table footer with this method. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    JavaScript syntax:

    -

    myTHEAD.insertRow(anIndex)

    Argument list:

    anIndex

    The row at which to insert the new TR object

    See also:

    TFOOT.insertRow()

    THEAD.rows[] (Collection) A collection of rows within a block of a table. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    Collection object

    JavaScript syntax:

    -

    myTHEAD.rows

    2269

    JavaScript Programmer's Reference

    This is not the same as the rows collection returned from a TABLE object. That is because the rows[] collection belonging to a THEAD object can only list those TR objects that are contained within the tags. See also:

    Collection object, TABLE.cells[], TABLE.cols, TABLE.rows[], TBODY.rows[], TFOOT.rows[], TR.rowIndex

    Property attributes: ReadOnly.

    THEAD.vAlign (Property) A control for the vertical alignment of cells within the THEAD object. Availability:

    DOM level – 1 JavaScript – 1.5 JScript – 3.0 Internet Explorer – 4.0 Netscape – 6.0

    Property/method value type:

    String primitive

    JavaScript syntax:

    -

    myTHEAD.vAlign

    The vertical alignment of the content within the table cells can be controlled across an entire THEAD extent with this property. The following keywords can be assigned to it: ❑

    baseline



    bottom



    middle



    top

    These may be also available on some implementations: ❑

    absbottom



    absmiddle



    baseline



    texttop See also:

    2270

    TBODY.vAlign, TD.vAlign, TFOOT.vAlign, TH.vAlign, TR.vAlign

    T – this (Keyword)

    this (Keyword) A reference to the receiving object. Availability:

    ECMAScript edition – 2 JavaScript – 1.0 JScript – 1.0 Internet Explorer – 3.02 Netscape – 2.0 Netscape Enterprise Server – 2.0 Opera – 3.0

    Property/method value type:

    An object

    JavaScript syntax:

    -

    this

    Every active execution context owns a this value. It is used for self-referring script statements. The specific this value of an execution context depends on the caller and the type of code being executed. This is determined on entry to an execution context. The this value associated with an execution context is immutable and therefore cannot be changed from a script. A this value is considered to be a primary expression. The this keyword is often used inside function bodies that are registered with a prototype. When it is executed, the function can refer to its owning object without having to know what sort of object it is. We can use this to write a function that can be used with several kinds of object. If the this keyword is used inside an event handler, it refers to the object that the event belongs to. We can exploit this to build event handlers that support many objects and can be called by different event types. If the this keyword is used outside of all functions (in global code) it refers to the Global object. A this property used in a script will therefore return that global object. In fact it will return an object of type Window. Other object types will be returned according the context in which the property is applied. The example shows how the this keyword can be used to enhance the prototype of an object.

    Example code:





    See also:

    "Field"); myAnimal + "
    "); myAnimal.species + "
    "); myAnimal.habitat + "
    ");

    Execution context, Method, Primary expression, Reference

    Cross-references: ECMA 262 edition 2 – section – 10.1.6 ECMA 262 edition 2 – section – 10.1.7 ECMA 262 edition 2 – section – 11.1.1 ECMA 262 edition 3 – section – 10.1.6 ECMA 262 edition 3 – section – 10.1.7 ECMA 262 edition 3 – section – 11.1.1 Wrox Instant JavaScript – page – 30 Wrox Instant JavaScript – page – 53

    Thousands separator (Definition) A special locale specific character for indicating groups of digits. See also:

    2272

    Decimal point (.), Localization

    T – throw (Statement)

    throw (Statement) Throw a custom exception in the hope it will be caught by an error handler. Availability:

    ECMAScript edition – 3 JavaScript – 1.5 JScript – 5.0 Internet Explorer – 5.0 Netscape – 6.0

    The throw statement provides a way to create an exception which will be passed to an associated catch() handler in a try ... catch structure. It is really intended to be used in that context, but you can use it outside of a try ... catch structure and trap the exception with the normal onError event handling support. You can use this mechanism to generate an error, perhaps as a result of testing some value. Placing a throw statement into your code will force the error handling to be invoked. However if you use it outside of a try ... catch block, the browser error handling will generate an error due to there being no way of catching the thrown event. It forces an error dialog, but not the one you wanted. You need to use a throw with a try ... catch block to force the catch code to be called. You can work around this by assigning an error handler function to the onerror property and making sure that the error handler returns a Boolean true value to signify that the error has no further processing required.

    Warnings: ❑

    This is not supported by Netscape Enterprise Server 3, and so its error handling capabilities are not available server -side.



    When using MSIE version 5 on the Macintosh platform, if you set the LANGUAGE HTML tag attribute of the enclosing

    See also:

    catch( ... ), Error object, EvalError object, Exception handling, finally ..., RangeError object, ReferenceError object, SyntaxError object, try ... catch ... finally, TypeError object, URIError object

    Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.2 ECMA 262 edition 3 – section – 12.13

    throws (Reserved word) Reserved for future language enhancements.

    Refer to: Reserved word

    Cross-references: ECMA 262 edition 2 – section – 7.4.3 ECMA 262 edition 3 – section – 7.5.3

    Time from year (Time calculation) A date and time algorithm defined by ECMAScript. Availability:

    ECMAScript edition – 2

    Property/method value type:

    Number primitive

    To calculate any time values relative to the start of a year, we need to know what instant the year began. All non-leap years have 365 days with the usual number of days in each month. Leap years have an extra day in February. The calculation shown below uses known leap years and non leap years to adjust the day numbers and yield the day number of the first day of the given year and then use that to work out the time in milliseconds when the year started: DayFromYear(y) = 365 * (y - 1970) + floor((y - 1969) / 4) - floor((y - 1901) / 100) + floor((y - 1601) / 400) msPerDay = 86400000TimeFromYear(y) = msPerDay * DayFromYear(y)

    2274

    T – Time from year (Time calculation)

    Subtracting this value from any absolute time value gives you a millisecond accurate offset from the beginning of the specified year.

    Example code: // Work out days and milliseconds at start of a year var msPerDay = 86400000; // Test day from year document.write("
    "); for(var ii=1980; ii), Greater than or equal to (>=), Identically equal to (===), Less than (=), Identically equal to (===), Identity operator, Less than (