|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
This example works as follows. First, a flag is set establishing whether the browser is Netscape Navigator or Microsoft Internet Explorer: if (navigator.appName == Netscape) ieflag = false else ieflag = true This flag is used throughout the rest of the document to determine which actions to perform.
See Browser Detection Scripts, p. 672. If this page is loaded into Netscape Navigator (see Figure 24.3), the second <STYLE> tag contains the information that is used to change the formatting information of the first paragraph of text. <STYLE TYPE=text/javascript> classes.myClass.P.fontSize = 12pt classes.myClass.P.fontFamily = Verdana </STYLE> This is what Netscape refers to as a JavaScript Accessible Style Sheet. It specifies the format of the paragraph class known as myClass. This style is applied to the first paragraph through its <P CLASS=myClass> tag. After the document is loaded and displayed into Netscape Navigator, however, the format cannot be changed. If this page is loaded into Internet Explorer, the following JavaScript lines change the format of the first paragraph of text after it is loaded and displayed: if (ieflag) { document.all.tags(P).item(0).style.fontSize = 12pt document.all.tags(P).item(0).style.fontFamily = Verdana }
Unlike Navigator, Internet Explorer can also change the format of text dynamically. This is done in this document by attaching the changeStyle() function to the onClick event of the button. function changeStyle() { if (ieflag) { document.all.tags(H1).item(0).className = clicked document.all.tags(P).item(1).style.fontSize = 18pt } } The changeStyle() function changes the format of the second paragraph by directly manipulating its style properties, and it changes the format of the heading by attaching a different style sheet class to it (see Figure 24.4).
Web Browser Object ModelThe Document Object Model used by Netscape Navigator and Microsoft Internet Explorer lies at the heart of their implementations of Dynamic HTML. Netscapes implementation, and its extensions to the object model, are not as extensive as Microsofts. Still, a number of important extensions enable you to increase capability in your HTML documents. Microsofts new object model, on the other hand, is a much more significant extension of the object models of the past for either browser. In the past, you were limited mainly to accessing and manipulating the Web browser windows and only a few aspects of the current document, such as the hypertext links, HTML Forms, and images. Now, Microsofts Dynamic HTML has extended the object model to every HTML tag. It is now possible to examine or set properties for any tag within an HTML document or to set up events that are attached anywhere. Microsofts Dynamic HTML documentation Web site includes some good examples of this, enabling you to dynamically change the content included in an outline, expanding or compressing it in response to user input. The differences and additions to the Web Browser Object Models introduced by Netscape and Microsoft are discussed in greater depth and detail in the following two chapters. The next two sections highlight some of the more important additionsin this case, changes to the Web browser event model and how you use it. See Internet Explorer Document Object Model, p. 638. The traditional event model enabled you to respond to a limited number of events that could be triggered by the actions of your users. Table 24.1 summarizes the most important of these events, along with their description and the HTML elements to which they applied.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |