JavaScript & DHTML Cookbook, Second Edition
by Danny Goodman
The unconfirmed error reports are from readers. They have not yet been
approved or disproved by the author or editor and represent solely the
opinion of the reader.
Here's a key to the markup:
[page-number]: serious technical mistake
{page-number}: minor technical mistake
...
...
in the example, it likely is added by mistake, and should be removed altogether. [405] final function within Example 13-1 (DHTML3API.js); The DHTML3API.js function labeled "getInsideWindowHeight" contains flow control which is inconsistent with API as a whole and fails to produce the desired result when processed by the IE6. In the following reproduction I have highlighted the erroneous clause with '*>' ================================== *incorrect* // Return the available contetn height space in browser window getInsideWindowHeight : function () { if (window.innerHeight) { return window.innerHeight; *> } else { *> if (document.body.clientHeight != document.body.parentNode.clientHeight) { *> // measure the html element's clientHeight *> return document.body.parentNode.clientHeight; *> } else { *> return document.body.clientHeight; *> } } return null; } =============================================* When compared with a sister reference authored by Danny Goodman, "Dynamic HTML: The Definitive Reference, Third Edition" (isbn 0-596-52740-3), which includes the same API labeled DHTMLapi3.js, the consistent and correct flow control for this function can be found... ==================================== *correct* // Return the available content height space in browser window getInsideWindowHeight : function () { if (window.innerHeight) { return window.innerHeight; } else if (this.browserClass.isIECSSCompat) { // measure the html element's clientHeight return document.body.parentElement.clientHeight; } else if (document.body && document.body.clientHeight) { return document.body.clientHeight; } return null; } =============================================* As a side note, both publications include inconsistent terminators within the DHTMLAPI.init() function. They work, but could cause some confusion; especially in light of DHTMLAPI object's short-cut syntax. [411] Javascript solution, 13.6.2 Code; the last two lines of the javascript are missing the - such that they mean something else and don't work correctly: posElem.style.left = offsetLeft + parseInt(baseElem.offsetWidth/2) parseInt(posElem.offsetWidth/2) + "px" posElem.style.top = offsetTop + parseInt(baseElem.offsetHeight/2) parseInt(posElem.offsetHeight/2)+ "px" each of these are missing the - sfter /2) and sould read instead posElem.style.left = offsetLeft + parseInt(baseElem.offsetWidth/2) - parseInt(posElem.offsetWidth/2) + "px" posElem.style.top = offsetTop + parseInt(baseElem.offsetHeight/2) - parseInt(posElem.offsetHeight/2)+ "px" [441-442] Entire Example; The example does not work. I retyped the example from the book, correcting the stray closing brace on page 442 and the example didn't work. I then downloaded the code from the website, removed the error-producing dots in the middle (why not a comment set off from the rest of the code or a note in the text of the book) and still saw... nothing. Firefox 2.0.3/Mac OS X [503] Bottom code example; An earlier example used quotes, it expands to show pictures. It shows this code: var imgLinks = new Array(); imgLinks[imgLinks.length] = {src:"images/prods/x25.jpg", url="products/x25.html", alt="X25 Super Widget"}; ... function getRandomImage(imgElemID) { var currIndex = Math.floor(Math.random() * (quotes.length)); ... The last line should be var currIndex = Math.floor(Math.random() * (imgLinks.length)); Also, the declaration of imgLinks element is wrong: src:"" and url="" cannot both be right: Recipe 3.8 suggests it's src:"".