cookie

NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 IE5.5 Compatibility The cookie mechanism in a Web browser lets you store small pieces of information on the client computer in a reasonably secure manner. In other words, when you need some tidbit of information to persist at the client level while either loading diverse HTML documents or moving from one session to another, the cookie mechanism saves the day. You can find Netscape's technical documentation much of which is written from the perspective of a...

Listing The Main Program mapgamehtm

lt HEAD gt lt TITLE gt Map Game lt TITLE gt Most of the positionable elements have their CSS properties established in the lt STYLE gt tag at the top of the document. Positionable elements whose styles are defined here include a text label for each state, a map for each state, and a congratulatory message. Notice that the names of the label and state map objects begin with a two-letter abbreviation of the state. This labeling comes in handy in the scripts when synchronizing the selected map...

preventDefault

While NN6 continues to honor the original way of preventing default action for an event handler that is, having the last statement of the event handler evaluate to return false , the NN6 event model provides a method that lets the cancellation of default action take place entirely within a function invoked by an event handler. For example, consider a text box that is supposed to allow only numbers be typed in it. The onKeyPress event handler can invoke a function that inspects each typed...

Nested objects and prototype inheritance

When you begin nesting objects, especially when one object invokes the constructor of another, there is an added wrinkle to the prototype inheritance chain. Let's continue with the car object defined earlier. In this scenario, consider the car object to be akin to a root object that has properties shared among two other types of objects. One of the object types is a company fleet vehicle, which needs the properties of the root car object plate, model, color but also adds some properties of its...

BODY Element Object

For HTML element properties, methods, and event handlers, see Chapter 15.

Times Not on Your Side

Thanks to over fifteen years' experience programming applications that involve tracking time, I am overly sensitive to the way computers and programming languages treat time on a global basis. This issue is a thorny one, what with the vagaries of Daylight Savings Time and time zones in some parts of the world that differ from their neighbors by increments other than whole hours. In the case of working with time in JavaScript, you're at the mercy of how the browser and JavaScript interpreter...

Listing Controlling Window Chrome

lt TITLE gt Bars Bars Bars lt TITLE gt lt SCRIPT LANGUAGE JavaScript gt store original outer dimensions as page loads var originalLocationbar window.locationbar.visible var originalMenubar window.menubar.visible var originalPersonalbar window.personalbar.visible var originalScrollbars window.scrollbars.visible var originalStatusbar window.statusbar.visible var originalToolbar window.toolbar.visible generic function to set inner dimensions function toggleBar bar bar.visible bar.visible restore...

Listing Adding a ReadOnly Prototype Property to All HTML Element Objects

lt SCRIPT LANGUAGE JavaScript1.5 gt if HTMLElement function var result elementNodes 0, textNodes 0 for var i 0 i lt this.childNodes.length i switch this.childNodes i .nodeType case 1 To access the property, use it like any other property of the object. For example var BodyNodeDetail document.body.childNodeDetail The returned value in this example is an object, so you use regular JavaScript syntax to access one of the property values var BodyElemNodesCount

nextSibling previousSibling

Value Object reference Read-Only NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 IE5.5 Compatibility A sibling element is one that is at the same nested level as another element. For example, the following P element has two child nodes the EM and SPAN elements . Those two child nodes are siblings of each other. lt P gt MegaCorp is lt EM gt the lt EM gt source of the lt SPAN gizmos. lt P gt Sibling order is determined solely by the source code order of the elements. Therefore, in the previous example, the...

Listing Using the insertBefore Method

lt TITLE gt insertBefore Method lt TITLE gt lt SCRIPT LANGUAGE JavaScript gt function doInsert form if form.newText var newChild document.createElement LI newChild.innerHTML form.newText.value var choice var insertPoint isNaN choice lt H1 gt insertBefore Method lt H1 gt lt HR gt lt FORM onSubmit return false gt lt P gt Enter text or HTML for a new list item lt INPUT TYPE text NAME newText SIZE 40 VALUE gt lt P gt lt P gt Before which existing item lt SELECT NAME itemIndex gt lt OPTION VALUE...

isChar

NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 IE5.5 Compatibility You can find out from each keyboard event whether the key being pressed is a character key by examining the isChar property. Most typically, however, you are already filtering for character or non-character keys by virtue of the event handlers used to capture keyboard actions onKeyPress for character keys onKeyDown or onKeyUp for non-character keys. Be aware that the isChar property returns inconsistent values even for the same key in...

Text fields and events

Focus and blur also interact with other possible user actions to a text object selecting and changing. Selecting occurs when the user clicks and drags across any text in the field changing occurs when the user makes any alteration to the content of the field and then either tabs or clicks away from that field. When you design event handlers for fields, be aware that a user s interaction with a field may trigger more than one event with a single action. For instance, clicking a field to select...

Adding a prototype

A custom object is frequently defined by a constructor function, which typically parcels out initial values to properties of the object, as in the following example function car plate, model, color this.plate plate this.model model this.color color var carl new car AB 123, Ford, blue NN4 and IE4 offer a handy shortcut, as well, to stuff default values into properties if none are provided the supplied value is null, 0, or an empty string . The OR operator can let the property assignment...

deleteCell ceHIndex insertCell ceHIndex

Returns Nothing Reference to New Cell. NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 IE5.5 Compatibility The act of inserting a row into a table is not complete until you also insert cells into the row. The i nsertCell method does just that, with a parameter indicating the zero-based index of the cell s position among other cells in the row. A value of -1 appends the cell to the end of existing cells in the row. When you invoke the i nsertCell method, it returns a reference to the new cell. This gives...

escapeURIString [ unescapeescapedURIString

NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 IE5.5 Compatibility If you watch the content of the Location field in your browser, you may occasionally see URLs that include a lot of symbols plus some numbers. The format you see is URL encoding more accurately called URI encoding Uniform Resource Identifier rather than Uniform Resource Locator . This format allows even multiple word strings and nonalphanumeric characters to be sent as one contiguous string of a very low, common-denominator character...

Plugin detection in IEWindows

IE4 provides some built-in facilities that may take the place of plug-in detection in some circumstances. First of all, it s important to recognize that IE Windows does not use the term plug-in in the same way that Netscape and IE Mac use it. Due to the integration between IE and the Windows operating system, IE Windows employs system-wide ActiveX controls to handle the job of rendering external content. Some of these controls are designed to be accessed from outside their walls, thus allowing...