|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Listing 26.3 DynCon.htmReal-time Changing of HTML Document Contents Using the innerHTML Property <HTML> <HEAD> <STYLE> SPAN,P {font-family: Verdana; font-size: 18pt; font-weight: bold} </STYLE> <SCRIPT> function errortrap(msg,url,line){ return true } onerror = errortrap; </SCRIPT> <TITLE>Dynamic Content Using innerHTML</TITLE> </HEAD> <BODY onload=stuff() onmouseover=update()> <CENTER> <H1>Dynamic Content Using <EM>innerHTML</EM></H1> <HR> <P> <SPAN>This</SPAN> <SPAN>paragraph</SPAN> <SPAN>contains</SPAN> <SPAN ID=wordCount>???</SPAN> <SPAN>words</SPAN>. <SPAN>The</SPAN> <SPAN>mouse</SPAN> <SPAN>is</SPAN> <SPAN>currently</SPAN> <SPAN>over</SPAN> <SPAN>the</SPAN> <SPAN>word</SPAN> <BR><SPAN ID=currentWord STYLE=color:#0000FF;font-size:36pt>n/a</SPAN><BR> <SPAN>In</SPAN> <SPAN>this</SPAN> <SPAN>paragraph</SPAN>, <SPAN>this</SPAN> <SPAN>is</SPAN> <SPAN>word</SPAN> <SPAN>number</SPAN> <BR><SPAN ID=currentWordNum STYLE=color:#0000FF;font-size:36pt>n/a</SPAN> </P> <HR> </CENTER> <ADDRESS> Jim ODonnell, <A HREF=mailto:odonnj@rpi.edu>odonnj@rpi.edu</A> </ADDRESS> </BODY> <SCRIPT LANGUAGE=JScript> var oldObject function stuff() { oldObject = null wordCount.innerHTML = document.all.tags(SPAN).length } function update() { if (window.event.srcElement.tagName == SPAN) { if (oldObject) oldObject.style.fontFamily = Verdana oldObject = window.event.srcElement oldObject.style.fontFamily = Lucida Handwriting for (i = 0;i < document.all.tags(SPAN).length;i++) if (oldObject == document.all.tags(SPAN).item(i)) currentWordNum.innerHTML = i + 1 currentWord.innerHTML = oldObject.innerHTML } else { if (oldObject) { oldObject.style.fontFamily = Verdana oldObject = null currentWordNum.innerHTML = n/a currentWord.innerHTML = n/a } } } function errortrap(msg,url,line){ // alert(msg); return true; } onerror = errortrap; </SCRIPT> </HTML> The three main sections of interest in this example are the main document text (contained within the <P> container tag) and the two JavaScript functions, stuff() and update(). This application determines which word in the paragraph (if any) the mouse is over and changes the text to display this word as well as its position within the paragraph. To help accomplish this, each of these sections does the following:
Dynamic HTML Events and the event ObjectIn addition to making HTML documents more responsive by enabling you to attach events and manipulate the properties of virtually any HTML tag, Microsofts Dynamic HTML also has increased the number of HTML events that the Web browser can sense and respond to. This section identifies what most of these events are and shows what triggers them.
|
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. |