|
|
Introduction to the Object Model(Properties, Events, and Methods)Since JavaScript is supported by IE 3+ and Netscape 3+, with JavaScript, you don't have to worry about separate versions, you just have to worry about browser compatibility. Each browser version supports a slightly different implementation of JavaScript, so you really should test each page with IE 3 and 4, and Netscape 3 and 4. If you want to, you can also test it with Netscape 2 (you can still download it from Netscape's site, and it supports JavaScript). If you need for the functions of your script to function in ALL browsers, I suggest that you consider a server-based approach, using CGI programming. I have provided an example of a forwarding page which separates users capable of JavaScript from others, so that if you want to write a version which uses JavaScript and another which uses some other technology, you can easily do so. Now, some pieces of code are built-in to JavaScript. Some types of code which are always available to JavaScript are statements, operators, and built-in functions. In addition to these, JavaScript in web pages also has access to the browser's object model. This is a structured way of looking at how the browser works. It gives access to properties, events and methods. Events let you know that something has happened, such as a mouse click, and let you respond. Properties store information, such as background color, and often can be changed. Properties which cannot be changed are called read-only properties. Methods are the things the object can do. Examples of methods are alert, which displays a message, and write, which writes information to a document. As has already been mentioned, several browsers support JavaScript, but each version has a different object model. IE4's object model is much more extensive than IE3's or even NN4's. It is very tempting to ignore the version 3 browsers in favor of the new options provided by version 4 with Dynamic HTML, but many people still use version 3, and it is unwise to ignore a large portion of the audience. Here's a simplified look at the IE3 Object Model. (Netscape 3's OM also contains an Image object. Netscape 4 mostly just adds new events, properties and methods. IE 4 allows access to every object in a document.)
If those ellipses (...) look suspicious to you, it's for good reason. They indicate that there may be more than one of that object. Each frame is treated as a window object, and may contain other frames. Objects are referred to using dot notation, separating the objects by a dot. For example, to refer to the Alert method, you could use window.alert. If you wished to refer to the background color property of the document, you could use window.document.bgColor. In most cases, the window object is left out. It is understood by the browser if it is omitted, because Window is the top-level object. Thus, the previous examples could also be written alert and document.bgColor. Further information on the object model can be found at the IE Object Model Reference and the Netscape JavaScript Reference (Chapters 5-8). Also, you can see what functions are built into JavaScript in the MS JavaScript Reference and the Netscape JavaScript Reference.
|
|