JavaScript Bible (4th Edition) Support Center
Important announcement for early JSBible 4 buyers: You may need to order a free replacement for the CD-ROM that came with your book. The two things to look for are as follows:
- If the
JSB4
directory contains individual PDF files for each chapter and appendix, many of those files (dated 1998) are from the 3rd edition, not the current 4th edition. (I learned about this the day after I got home from the hospital--I thought I was going to pop a staple!). - The descriptions of the CD contents in Appendix E (p.1165) and in the ReadMeFirst file refer to "Reference Examples from Parts III and IV." These are the examples sections from the text that have been consolidated into Appendix F. The PDF file for Appendix F is on the CD-ROM you have, so you can refer to it until you receive your replacement CD. The HTML listings (many of which provide live pages to support the examples sections) can be found in the
Author_Files\Listings
directory, just like earlier editions.
To order your replacement CD, send an e-mail to techsupdum@wiley.com. Or you can call Hungry Minds (now part of Wiley) at 800-762-2974 (toll-free in U.S.) or 317-572-3993 (from outside U.S.). Be sure to mention the ISBN of the book in your correspondence. The publisher extends its apologies for this inconvenience.
New Index File for CD-ROM Listings
Changes to the innards of Netscape 6.1 and later prevent the index.html file located in the Author-Files/Listings directory on the CD-ROM to work properly with those browsers. I have reworked the index file so that it utilizes dynamic table updating in IE4+/Windows and NN6+. All other browsers continue with the old scheme of a dynamic frameset. There is some interesting scripting there for you to enjoy. If you have copied the Listings directory to your local hard disk, download the new version, and use it instead of the original index.html page as your gateway to the hundreds of listings.
Corrections & Updates
Corrections or changed information for the first printing (corrections will be incorporated into subsequent printings, so not all of the following items may apply to your copy of the book.):
- Page 25. Steps 1 and 3 near the top of the page should display the Macintosh Command symbol (you know, that curlicue thingy) instead of the umlauted O.
- Page 34. In the "JavaScript in Action" section, the referenced tutor1.htm file is missing from the CD-ROM. But you can access the applications by way of the Author_Files/Listings/index.html file, from which you can choose chapters 48 through 57.
-
Page 42. The hidden input element is missing from Figure 4-6. That element has been scriptable since Day One, although there obviously are no event handlers for it. But you can use scripts to set the
value
property to modify data submitted with the form behind the scenes. - Page 74. The pointer at the bottom of the page should be to Page 47 in Chapter 4.
- Page 79. The first sentence of the fourth full paragraph should be: "Because these two conversion functions evaluate to their results, you simply insert the entire function wherever you neeed a string value converted to a number."
- Page 81. Clarification for Exercise Question #2: Treat the statements as a sequence of statements, where each one relies on the result of the one before it.
-
Page 98. In the listing for Question #2 (and the corresponding answer on page 1149), the exponent notation (e.g.,
1e6
) should be paired such that1e5
should also read1e6
like the line above it; the second pair should both be1e3
. This effects calculated results if you were to use the function on a page, but not the other intentional errors in the listing that you need to correct for this exercise. - Page 103. At the very bottom of the page, the chapter reference should be to Chapter 6."
- Page 122. In the last paragraph, the pointers to figures should be to Figures 4-6 and 8-1.
-
Page 127. In the next to last paragraph, fifth line, there should be a space between
return
andfalse
. -
Page 141. In Exercises question #3, the seventh code line should end with
toLowerCase()
to be in sync with the solution provided on page 1156. You can write the solution using either string method, but the test for equality would require"E"
if you stay withtoUpperCase()
. The important point to remember is that when you want to test for case-insensitive user input, you should convert the input to either all uppercase or all lowercase, and then check the string equality of the format you choose. - Page 148. The chapter pointer for the Decision Helper should be to Chapter 55.
-
Page 151. In Listing 11-2, the
<FORM>
and</FORM>
tags are obviously in the wrong order. (It's a long story, and I'm the doofus who screwed it up.) - Page 152. In Listing 11-3, a closing /BODY tag belongs between the closing /FORM and closing /HTML tags.
- Page 157. The "desk1.gif" and related images are not in the Chapter 12 directory of the CD-ROM, as indicated above Listing 12-1. But you can find all four images in the Chapter 16 directory if you wish to try your hand at this example (as I recommend you do).
-
Page 193. In the second full item about control structures, the
do-while
andswitch
constructions were inaugurated with JavaScript 1.2. The browser versions shown there are correct. - Pages 198 (Figure 14-1) & 210 (Figure 14-2). Due to production snafus, the background shading for these illustrations doesn't appear, and the vertical line extending from the bottom of the "document" box to the next lowest horizontal line is missing. For Figure 14-1, turn to Figure 8-1 on Page 100. You can see the shaded version of Figure 14-2 on the back page of any of the booklet versions of the Quick Reference PDF files on the CD-ROM.
-
Page 202. Ignore the last three paragraphs of the upper part of the page. The
onload()
function technique no longer works in a lot of browsers. - Page 214. Typo in paragraph two of the "DOM levels" section. The third word of line four should be plus, not plug.
-
Page 248. Typo in the "Related Items" section near the bottom of the page. The method name should be
scrollIntoView()
. -
Page 250. The
attributes
property, as noted, returns an array ofattribute
object references. IE 5 and 5.5 for Windows has a sloppy implementation of that object, so if you use The Evaluator to explore this property of, say, the table element (as suggested in Appendix F), a few of the attribute values are out of whack. IE 6, however, does it right, as does NN 6 and IE 5 for the Mac. In any case, the canonical way to read/write the value of an attribute is through the element'sgetAttribute()
andsetAttribute()
methods. -
Page 253. The compatibility chart for
childNodes
should read IE 5 and IE 5.5. -
Page 272. Discussion about the shared
nextSibling
andpreviousSibling
properties incorrectly speaks in terms of sibling elements, when in truth these properties reference nodes. In the example shown on this page, theEM
element has both a previous and next sibling -- both of which are text nodes of theP
element. On a related subject, Netscape 6 and later treat source code white space (e.g., carriage returns) as text nodes. For example, if you format your source code like this:<DIV>
the
<P>...</P>
</DIV>P
element has both a previous and next sibling in Netscape 6+. Those sibling nodes are text nodes, each containing a single carriage return character. IE, on the other hand, ignores carriage return whitespace, and would report that theP
element has no sibling nodes.
This Netscape treatment of whitespace is a controversial subject. One could argue (interpret the W3C standards) that these whitespace text node siblings are correct. But for scripters, they get in the way, forcing you to verify thenodeType
of a sibling to find adjacent elements. You can see the disparity of node treatment by invoking thewalkChildNodes(document.body)
function in The Evaluator under IE and NN6+. -
Page 298. Clarification: the
attachEvent()
anddetachEvent()
methods are not supported in IE5/Mac. -
Pages 319-20. By way of clarification, the
insertBefore()
method returns a reference to the node that has just been inserted; also, if the node referenced in the parameter is an existing node from the document tree, the existing node is removed from its original place, and inserted where directed by theinsertBefore()
method. -
Page 331. The last sentence of paragraph 3 (for the
replaceChild()
method) should read:"If you simply want to change an element, you can do so more directly in IE5+ with the
The W3C DOM provides no direct method for replacing an element from the point of view of that element -- only from its parent.swapNode()
orreplaceNode()
method." - Page 344. In the subject of the first line should be "The event model in IE4+..."
-
Page 357. The IE-only code example for the
assureUpper()
function should be using theevent.keyCode
property in all instances. - Page 369. In Figure 16-2, the text inside the two boxes of the middle row should read Child Frame.
-
Page 424. The entry for
window.open()
mentions the optionalreplaceFlag
parameter, but doesn't describe what it does. This IE-only parameter is a Boolean value, but Microsoft's description of what it does makes no sense to me, and its observed behavior is counter-intuitive. Here's what I see with IE5.5/Win98 with a name assigned to the second parameter of theopen()
method, and that method invoked repeatedly with different URLs, but everything else the same: 1) with the replaceFlag value set totrue
, a new window opens for each invocation of the method; 2) with the replaceFlag value set tofalse
, the window created by the first invocation ofwindow.open()
has its contents replaced by the new URL, and I am left with only one subwindow. -
Page 426. In Table 16-3, the description of the
top
property should start with Vertical position - Page 431. In the last paragraph on the page, delete the parenthetical comment at the end of the first sentence. The behavior is the same for Netscape and Internet Explorer browsers.
-
Page 444. The last statement of the
findAndCycle()
function at the bottom of the page is missing some important single quotes, as follows:
intervalID = setInterval("cycleAnimation('" + elemID + "')", 500)
These single quotes force the string value ofelemID
to be treated as a quoted string when thecycleAnimation()
function fires in 500 milliseconds. -
Page 448. In the second paragraph of the description, the third line is missing an "s" on the property name:
window.dialogArguments
. - Page 522. The link to Bill Dortch's web site is no longer valid. He seems to have disappeared. If anyone has current contact information, please let me know.
-
Page 541. The last sentence of the
links
property description means that you have the same properties available to each member of thelinks
array as for thelocation
object. -
Page 563. In the syntax for the
document.open()
method, the second parameter is not a placeholder, but a constant:replace
. -
Page CD-58 (Chapter 19). In the big table, the fifth item in the lefthand column should read
InsertUnorderedList
. -
Pages 610-11. The descriptions of the
hspace
andvspace
properties have their orientations reversed.hspace
controls the left and right margins;vspace
controls the top and bottom margins. I must have been hypnotized by The Outer Limits on TV as a kid. - Page 638. Delete the word "they" from the end of the first line of full paragraph 2.
-
Page 656. Only the
<input>
type of button (and not the<button>
element) submits thevalue
attribute value with the form. A<button>
element submits the element's content (the string between the start and end tags) with the form. If you provide multiple submit buttons for a form, and want some button-specific data submitted with the form, use theonClick
event handler to assign the data to a hidden input field prior to submission. -
Pages 713. The IE-only
add()
andremove()
methods belong to theoptions
array object, and not individualoption
element objects, as indicated. The working example in Listing 26-2 demonstrates the correct usage. -
Page 751. Near the bottom of Table 29-2, the NN6 implementation of the cancel bubble action is
stopPropagation()
. Netscape also implements the IEcancelBubble
property, but that property is not part of the W3C DOM Event model. ThepreventBubble()
method was an older, preliminary implementation that I failed to replace in this table when Netscape and the W3C DOM finalized their syntax. -
Page 757. Table 29-4 should include the
dblclick
event type, which is implemented in IE4+ and NN4+ (continuing into NN6+). -
Page 758. Table 29-4 should not include the
scroll
event type, which is implemented only in IE4+. -
Pages 772-4. The IE
event.x
andevent.y
properties operate within the coordinate system of the event target'soffsetParent
element only when theoffsetParent
is a relative-positioned element. By coincidence thisoffsetParent
coordinate system also holds true for an absolute-positioned element that is a child of thebody
element (in non-standards-compliant mode) because the body is theoffsetParent
. But the intention of these two properties is to work within a relative-positionedoffsetParent
space. -
Pages 790-1. Netscape 6+ has a peculiarity with respect to the values returned by the
layerX
andlayerY
properties of the event object. If the event target is a text-based form control (textinput
element,textarea
, orselect
), the coordinate system for the two properties is confined to the element itself, even if the element is not positioned. This could bite you if you track the location of mouse events in these form controls (probably a rarity) via thelayerX
andlayerY
properties (an even rarer probability). -
Page 797. The last sentence of the
preventDefault()
description should read: "Invoking thepreventDefault()
method in NN6 is the equivalent of assigningfalse
toevent.returnValue
in IE4+." -
Page 929. The middle code example for the random number statement (it's actually a pseudo-random number generator) should be as follows:
Math.floor(Math.random() * (n - m + 1)) + m
wheren
is still the top number of the range andm
is the low number of the range. When the bottom of the range is 1, you can short circuit part of the expression, as shown in the third example for the roll of a die. -
Page 932. In the first paragraph under
MAX_VALUE
, the last line should list only two values (an extra comma throws things off). The values are1.7976931348623157 * 10308
and5 * 10-324
. -
Pages 942-3. In Table 36-1, the descriptions for the
getMilliseconds()
andgetUTCMilliseconds()
methods are not correct. These methods return the number of milliseconds (0 to 999) following the next lowest full second of the date object instance. In other words, if you created a date object exactly between 00:00:00 and 00:00:01, the value returned from both methods would be 500. -
Chapter 38 (CD-299 to CD-306). Let me clarify some things about the
multiline
property and what the whole "multiline" thing means in JavaScript regular expressions.Although Netscape 4+ implements a
multiline
property for theRegExp
static object, that is not normal, and is not supported elsewhere. Such a property is not part of the ECMA standard. The only place the property should be read is from an instance of aRegExp
object.The value of the regexp's
multiline
property is determined exclusively by the presence or absence of the 'm' flag in the object constructor (it's another flag just like the 'g' and 'i' flags). In other words, the scripter determines whether themultiline
property of the regexp object will betrue
by explicitly setting the 'm' flag, as in:
var re = /you/gm;
After the above statement executes,re.multiline
istrue
.Now, what does setting this flag mean? First of all, its importance is _very_ limited. Despite its name, the 'm' flag has no bearing on the search for text matches extending across multiple lines of text in a string. All searches work across multiple-line strings. Period.
The 'm' flag does apply, however, when the regular expression includes the
^
or$
symbols. For example, let's look at the^
symbol, which indicates that the pattern must start at the beginning of a string. Here are some examples, using the multiline string:
Are\n
The regexp
you\n
happy?
/you/
will find a match because the pattern "you" is someplace within the string.The regexp
/^you/
will _not_ find a match because the string does not start with the pattern "you".The regexp
/^you/m
will find a match because the 'm' (multiline) flag says it's OK to treat each physical line of a multiline string as a start of a string.You have to be careful when you deploy the 'm' flag because not all browsers recognize it. It works in IE 5.5 or later for Windows and NN 6 or later. Not for IE/Mac or NN 4. Using the 'm' flag causes script errors in the older browsers.
- Page 1005. I thought I fixed this 3rd edition error, but I guess not. In the paragraph following the syntax model, the second sentence should read: "Labels are surrounded by quotes when the labels represent string values of the expression." The example in Listing 39-6 clearly shows this.
-
Page 1006. In Listing 39-6, the second array constructor is missing parentheses:
var snacks = new Array()
-
Page 1023. The error numbers reported by IE have to be massaged a "bit" to obtain the number that corresponds to Microsoft's documented errors for IE/Windows. Use the Bitwise AND operator (
&
) and hexadecimal value FFFF to get a meaningful number:
var errNum = errorObj.number & x0FFFF
A list of IE runtime errors and their meaning can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsmscRunTimeErrors.asp. Of course these error reports are no more accurate or revealing than IE's frequently deceptive error messages that occur normally. - Pages 1106ff. The URLs shown as sources for more information about the IE/Windows objects are no longer valid (surprise, surprise!). The most recent URL for the ActiveXObject info is http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsobjActiveXObject.asp. The table of contents that appears in the frameset for that page includes links to most of the other objects described in this section of JSBible..
-
Pages 1109-1112. Microsoft must have realized what a potential security hole a client-controlled
FileSystemObject
could be. This ActiveX control is no longer accessible from client-side JavaScript (or VBScript).Update! Mats Lundgren from Sweden provides an example of how you can reach this ActiveX object, provided the user agrees to download and install a Visual Basic Control Cabinets File (the user gets a Security Warning before installation). Mats offers some sample code you can try at your own risk. The script portion is as follows:
function LoadFile()
{
CommonDialog1.ShowOpen();
var fileName = CommonDialog1.FileTitle;
var fObj = new ActiveXObject("Scripting.FileSystemObject");
var f = fObj.OpenTextFile(fileName);
var fileContents = f.ReadAll();
f.Close();
var iframeWin = window.message;
iframeWin.document.write(fileContents);
}
The HTML portion is as follows:
<BUTTON ONCLICK="LoadFile();">Open</BUTTON>
<OBJECT ID="CommonDialog1" WIDTH="0" HEIGHT="0"
CLASSID="CLSID:F9043C85-F6F2-101A-A3C9-08002B2F49FB"
CODEBASE="http://activex.microsoft.com/controls/vb5/comdlg32.cab">
<PARAM NAME="CancelError" VALUE="1">
<PARAM NAME="DialogTitle" VALUE="Select File">
<PARAM NAME="Filter" VALUE="(*.txt)|*.txt|(*.htm)|*.htm|All Files(**)|*.*">
</OBJECT>
-
Pages 1131. In the box for the
location
object, thesearch
property got cropped out inadvertently. Unfortunately, this goof propagates through all the printout versions of the Quick Reference on the CD. If you've printed out the Quick Reference, add thesearch
property underprotocol
. -
Page 1144. The answer for Question #2c should be:
General_Motors.Pontiac.GrandAm
-
Page 1154. The first part of the text answer to Question 2 does not correctly reflect the code (or what the question asks you to do). The Submit button has been replaced by a link (an <A HREF=...> tag), whose HREF attribute invokes a
javascript:
URL that fires thecheckForm()
function. Thevoid
operator prevents the link from doing anything other than activating the function when it is clicked.
The other part of the answer about removing theonSubmit
event handler is correct. -
Page 1157. In the answer to Question #4, the
<TITLE>
tag should read "Roll the Dice". This typo does not affect the operation of the code.
Updated Listings
-
Listing 16-13. This listing somehow escaped the CD-ROM. It provides a live example of the
window.pageXOffset
andwindow.pageYOffset
properties for Netscape Navigator 4 and 6. You can open the example here, and save it to your local hard disk. -
Listing 31-16. The
getClipRect()
function needs a revision to follow the correct way to represent thestyle.clip
property, with no commas between the length values. Here's the revision:// convert clip property string to an object
function getClipRect(elem) {
var clipString = elem.style.clip
// get rid of "rect("
clipString = clipString.match(/\(.*\)/)[0].substr(1)
// get rid of "px," and "px)"
clipString = clipString.replace(/px,*\)*/g,"")
// replace spaces with commas
clipString = clipString.replace(/\s/g,",")
// turn remaining string into an array
clipArray = clipString.split(",")
// make object out of array values
var clipRect = {top:parseInt(clipArray[0]), right:parseInt(clipArray[1]), bottom:parseInt(clipArray[2]), left:parseInt(clipArray[3])}
return clipRect
}You also need to change the style specification of the final
div
element to remove the commas:
clip:rect(0px 360px 180px 0px);
-
Listing 31-21. On page CD-250, the last line's
</LAYER>
tag should obviously be a</DIV>
tag.
More: Another reader wondered why the<DIV>
tag has a<SPAN>
tag nested inside. That element is an artifact from the original NN4 version of the script (from earlier in the chapter). Since I tried to demonstrate both IE and W3C DOM versions of the old stuff with the least disruption, I left the<SPAN>
in there. Fortunately, you don't have to play those nesting tricks in the IE or W3C DOMs because any element can be designated positioned. -
Listings 36-01 and 36-02. The
customDateString()
function in both listings goes too far to accommodate older browsers and historic dates. Assuming you don't need to work with dates prior to 1900, the next-to-last statement of of the function should be:
theYear += (theYear < 1900) ? 1900 : 0
If you need historical dates, change the comparison value to200
. This will take care of dates back to the year 200 A.D. and users of Version 2 and 3 browsers through the year 2099. After that, they should seek counseling. -
Listings 39-08 through 39-10. While paying attention to the exception handling, I let a simple error slip by that puts the wrong letter into the output text box. The last statement of the
getLetter()
function in all three of these listings should be:
fld.form.output.value = letters[inp - 1]
-
Listing 43-5 (CD-ROM). The
isNumber()
function is more robust by disallowing entry of only a decimal point and no numbers.// general purpose function to see if a suspected numeric input
// is a positive or negative number
function isNumber(inputVal) {
var oneDecimal = false
var digitCount = 0
inputStr = inputVal.toString()
for (var i = 0; i < inputStr.length; i++) {
var oneChar = inputStr.charAt(i)
if (i == 0 && oneChar == "-") {
continue
}
if (oneChar == "." && !oneDecimal) {
oneDecimal = true
continue
}
if (oneChar < "0" || oneChar > "9") {
return false
} else {
digitCount++
}
}
return (digitCount > 0)
}
} -
Listings 56-01 (mapgame.htm). I updated this file for better drag tracking. You can see the results in action and download the file from the directory.
Notes
-
Image Type
input
Elements. Perhaps for historical reasons (in DOM Level 0, the image typeinput
element was not addressable as an object), you cannot reference an image typeinput
element through the Level 0 referencing scheme ofdocument.formName.inputName
. Nor do these controls show up in the collection returned by a form'selements
property. The exception to this is IE/Mac, which does allow such references. -
mailto: URLs in Forms (Chapter 23) Implementation of e-mailed forms has been uneven through the years, and the situation gets only worse with Netscape 6 and 7. Although NN 4 supported this feature to a reasonable extent, the Mozilla browser at least through 1.0 (from which Netscape 7 comes) does not implement mailto: URLs for form actions as before. A hotly contested internal debate has raged for more than a year and a half on the issue, and the implementation target keeps pushing forward.
There is a crude workaround exclusively for NN6/7, but it has limitations. The workaround involves a magic hidden input field whose name and id arebody
:
<INPUT TYPE="hidden" NAME="body" ID="body">
Any string you assign to thevalue
property of that hidden field becomes embedded in the body of the resulting e-mail message. Specify the mailto: URL as before.
But there's a rub to this implementation: theMETHOD
attribute of the form must be set toget
for this magic hidden data to become embedded in the message. This is counter to thepost
method that IE and NN4 need to get the data attached/embedded into the message. It's not a big deal to set themethod
property of the form to"get"
while you're busy accumulating control names/values for the hidden "body" field. But, aget
method does not pass along the subject portion of the mailto: URL to the message. The message has no subject, and the user typically gets prompted to insert a subject.
This is a horrible mess, IMHO. It speaks volumes to why I never cared for e-mailing forms in the first place. Yes, the JSBible documents how to do it, but only because if it didn't, I'd be strung up from a high tree.
If anyone has good experience with free or low-cost form-processing sites (that let your pages submit forms to a real server CGI, which then forwards the data to you via e-mail), I'd like to pass along that info to others here. Not everybody has access to their Web servers to write their own Perl scripts for this kind of work. This "hands-off" form submission approach is important to lots of sites. -
Table Modification Methods (Chapter 27) A couple of references to the
TABLE.insertRow()
andTR.insertCell()
methods discuss the parameter -1 as a signal to append the new item to the end of the table or row. This parameter is unique to Internet Explorer. It is not specified in the W3C DOM, and Netscape 6+ does not recognize this value. To append a row or cell using these table insertion methods, use the length of the collection as the parameter. For example, to append a new table row to a table:
var oneTable = document.getElementById("myTable")
Remember that IE5/Mac does not handle table modification methods well at all. Regretably, I bypass that browser for dynamic tables.
var newTR = oneTable.insertRow(oneTable.rows.length)
- Accessing CD-ROM Files in Solaris 2.5.1. Reader Michael Bloom was kind enough to share a solution he tracked down for a problem he was having with the CD. If you are running Solaris 2.5.1 and cannot read all the files on the CD-ROM, you can obtain an official Sun patch that fixes the problem. The patch number is 104560-05 for Sparc and 104561 for Solaris/Intel.
-
SCRIPT.src Property (Chapter 20 on the CD). The
SCRIPT.src
property is read/write, but only IE actually loads a different .js file into the page when you assign a new URL to the property. IE doesn't exactly remove all pieces of the original .js file, but if the new file uses the same variable or function names as the original file, the new versions overwrite the same-named items from the original file. -
META.content
andMETA.httpEquiv
Properties (Chapter 20). Even though these two properties are read/write, altering their values after the page loads does not influence the way they work. Therefore, if you use a<META>
tag to perform automatic refreshes, you cannot modify the URL or delay after the browser reads the tag and its attributes. -
NN6.2
window.status
and Rollovers. Netscape 6 has a nasty bug that prevents changes to thewindow.status
property to stay visible when the property changes in response to a link rollover. It's partially a timing problem, and partially a problem that the default rollover behavior (showing the link's URL) cannot be overridden. There are 1.5 solutions to the problem:- Introduce an artificial delay in displaying the message so that it executes after the default action:
onmouseover="setTimeout('status=\'Bert & Ernie\'', 0);" onmouseout="setTimeout('status=\'\'', 0);"
- Leave your mouseover code the way it is, and assign your text to the link's
title
attribute so it appears as a tooltip.
If you have been following my advice, you're not putting mission-critical information into the statusbar, and not having your rollover message appear down there won't "break" your user interface. While the code fix (#1) works in all browsers, I'm not fond of introducing squirrely workarounds for a non-essential page feature to accommodate a small percentage of visitors.
- Introduce an artificial delay in displaying the message so that it executes after the default action:
-
NN6 Opacity Filter. Pages 871ff. talk about the IE/Windows
filter
object, which includes, among many other effects, the Alpha effect for controlling opacity of content. Although Netscape 6 doesn't have this ActiveX filtering stuff, it does have its own proprietary CSS-like syntax (and correspondingstyle
object property) for opacity. The CSS attribute name is-moz-opacity
(note the leading hyphen), and the property iselementRef.style.mozOpacity
. The value range is the same as the IE Alpha filter: a floating poing number between 0 and 1, with 1 being completely opaque. You can include both CSS syntaxes in a style rule, and each supporting browser will recognize its own syntax. Opacity/transparency is a cool effect, but also be sure to check the results on browser versions that don't support it. - About Pages Numbered CD-nnn. You will find plenty of Index references to pages numbered CD-nnn. These refer to pages from chapters that are published on the CD-ROM only. To find the chapter to which the cited page belongs, refer to the Table of Contents at the front of the book. As you thumb through the TOC, you'll see the chapters with CD numbers. Find the chapter that contains the desired CD-nnn page number to determine where to look for the page in the Acrobat file. (Yeah, I agree that it's not fun, but it's the best we could do to cram ten pounds of JavaScript into a five-pound book.)
- About Pointers to Chapters 43 and Later. If you see a reference in the text to more detailed discussion in Chapter 43 or later, be aware that these chapters are printed only in the Gold edition. But all is not lost: PDF versions of the Gold chapters are on the 4th edition's CD-ROM. Because most of the subjects covered by the Gold chapters (e.g., debugging, validation, etc.) were in earlier editions, I persuaded the publisher to continue offering those subjects on the CD-ROM for readers on tight budgets.
-
About the
alert()
Method. A reader who developed almost exclusively in the Windows environment relied on the beep generated when the Alert dialog appeared as an aural reminder alarm for an application. But be aware that the beep sound is not necessarily a part of thealert()
method. Some browsers and some operating systems sound a beep when the alert appears. Not all do. -
Dynamic Forms and Tables in NN6. Here's a weird one if your scripts need to add form controls and place them inside a table.
NN6 exhibits a few problems for which there are cross-browser workarounds. First, the most reliable way to dynamically include a TABLE inside an empty FORM element is to generate the TABLE element and its contents first in memory (usingdocument.createElement("TABLE")
and the various table object methods for inserting rows and cells -- also usingdocument.createElement()
to populate the cells with INPUT or other elements). Then use theappendChild()
method of the FORM element to insert the dynamically-generated table inside the FORM element.
At this point, however, NN6 exhibits a bug that prevents theform.elements
array from knowing about the controls inside the form. The controls are accessible by name, but only in a pure scripted reference (e.g.,document.myForm.myTextBox
). Usingdocument.elements[]
either with a numeric or name index does not work in NN6 when mixing dynamically generated tables and forms. Therefore, you can use theeval()
function to create a valid reference to the control (eval("document.myForm." + "elemName")
). If you assign an ID to the form controls, you can also usedocument.getElementById()
to reference the control (and thus avoid the dreadedeval()
function). -
Adjusting FRAMESET
cols
androws
Properties in NN6 There is a known bug in NN6 and NN6.1 that script control of thecols
androws
properties of a FRAMESET object does not refresh the layout when the change is made to a nested frameset. For a single frameset, as shown in JavaScript Bible 4th/Gold editions with Listings 16-46 through 16-48, the adjustments work fine for hiding/showing/adjusting frames on the fly.