Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Javascript for dummies 4th edition - Veer E.V

Veer E.V Javascript for dummies 4th edition - Wiley publishing , 2004. - 387 p.
ISBN: 0-7645-7659-3
Download (direct link): javascriptfordummies2005.pdf
Previous << 1 .. 32 33 34 35 36 37 < 38 > 39 40 41 42 43 44 .. 118 >> Next

Browser Object Models
Conceptually, Web pages are all the same: They’re displayed in browser windows, contain text and images, and so on. And, in fact, the World Wide Web Consortium (the W3C), an industry group responsible for many Web-related standards, has hammered out a standard document object model — a blueprint, if you will, that browser manufacturers can follow. (You can find a copy of the W3C’s DOM specification at www.w3.org/DOM.)
In reality, however, each browser manufacturer performs slightly different behind-the-scenes magic when it comes to implementing the DOM (and providing JavaScript support). What this means is that the browser models you work with in JavaScript — Microsoft’s Internet Explorer DOM and Netscape’s DOM — are similar but not identical.
Netscape Navigator
Netscape Navigator’s DOM describes all the objects you can access in JavaScript to create cool scripts that execute flawlessly in Netscape Navigator.
Chapter 4: Getting Acquainted with the Document Object Model
When you want to reference any of the following objects in your script, you use that object’s fully qualified name, as shown in the Syntax column of the following list. The window object is the only exception to this rule. By default, every Web page contains one all-encompassing, granddaddy window, no matter how many additional windows you choose to include. Because this overall window is a given, you don’t have to mention it specifically when you refer to one of the objects that it contains.
For example, the following two JavaScript code snippets both set the src property of an Image object named myImage equal to "happycat.jpg":
window.document.myForm.myImage.src="happycat.jpg"

document.myForm.mylmage. src="happycat.jpg"
The following is a short list of the basic objects that you work with in Netscape Navigator. You can find a list of all the objects in the DOM implementation for Navigator 7.1, including associated properties, methods, and event handlers, in Appendix C. Or check out Netscape’s exhaustive DOM reference at www.mozilla.org/docs/dom/domref/dom_shortTOC.html. Object Syntax
window window (optional)
document document
applet document.applets[0]
anchor document. someAnchor
area document. someArea
classes document.classes
form document. someForm
button document. someForm.someButton
checkbox document. someForm.someCheckbox
fileUpload document. someForm.someFileElement
hidden document. someForm.someHidden
image document. someForm.someImage
password document. someForm.somePassword
radio document. someForm.someRadio
reset document. someForm.someReset
select document. someForm.someSelect
submit document. someForm.someSubmit
text document. someForm.someText
textarea document. someForm.someTextarea
ids document.ids
layers document.layers
link document. someLink
(continued)
98 Part I: Building Killer Web Pages for Fun and Profit
Object Syntax
object plugin tags frame, parent, self, top history location locationbar menubar document. someObject docment.embeds[0] document.tags (all of these are also synonyms for window) history location locationbar menubar
navigator navigator
personalbar personalbar
scrollbar scrollbar
statusbar statusbar
toolbar toolbar
JavaScript data types
Much of what you want to do with a JavaScript script involves programmer-defined objects, such as the values that a user types into your HTML form, some calculations that you make based on those values, and so on.
Most programming languages require you to declare special placeholders, called variables, to hold each piece of data you want to work with. Not only that, but most programming languages require you to specify — up front — what type of data you expect those variables to contain. (This requirement makes it easy for those languages’ compilers but tough on us programmers!)
JavaScript expects you to declare variables to represent bits of data, too. But because JavaScript is a loosely typed language, you don’t necessarily have to declare the type of a variable up front, nor do you have to perform cumbersome type conversions the way you do in languages like C and C++. Here’s an example:
var visitor // Defines a variable called "visitor” of
// no particular type
var v s і tor = "george” II Resets "v s tor” to a text string
var v s tor = З II Resets "v s tor” to a numeric value
var v s tor = null II Resets "v s I tor” to null
You can get away without specifying string or numeric data types explicitly, as shown in this code snippet, because the JavaScript interpreter takes care of figuring out what type of value is associated with any given variable at runtime.
Chapter 4: Getting Acquainted with the Document Object Model
x$tBEH
There are two data types that JavaScript requires you to explicitly specify: the Array and Date data types. You must declare variables of type Array and Date explicitly because the JavaScript interpreter needs to know certain extra details about these types of values in order to store them properly.
Previous << 1 .. 32 33 34 35 36 37 < 38 > 39 40 41 42 43 44 .. 118 >> Next