Documentos de Académico
Documentos de Profesional
Documentos de Cultura
12.1 Introduction
Use JavaScript to manipulate every element of XHTML document from a script Reference for several of JavaScripts builtin objects Demonstrates the capabilities
Exhaustive list
http://www.devguru.com/Technologies/ecmascript/quickref/js_objects.html
String
Mth d e o c a A ( in e ) hrt dx
c a C d A ( in e ) hroet dx c n a ( s in ) o c t tr g
lsIdxf atneO( s b tr g in e ) u s in , d x
D s r tio e cip n Rtun as in c n in gth c aa te a th s e if din e . I th r isn e r s tr g o ta in e h r c r t e p c ie d x f ee o c a a te a th in e , c a A r tun a e p s in . T ef s c a a te is h r c r t e d x h r t e r s n mty tr g h ir t h r c r lo a da in e 0 c te t d x . Rtun th Uic d v lu o th c aa te a th s e if din e . I th r is e r s e n o e a e f e h r c r t e p c ie d x f ee n c aa te a th in e , c a C d A r tun N N( o aNme ) o h r c r t e d x h r o e t e r s a Nt u b r . C n a n te itsa g mn toth e do th s in th t in o e th mth d o c te a s ru et e n f e tr g a v k s e e o . T es in in o in th mth disn t md ie ; in te dan w t i gis h tr g v k g is e o o o if d s a e Srn r tun d T ismth disth s m a a d gtw s in sw th sr g e re. h e o e a e s d in o tr g ith e t in c n a n tio o ea r+( .g s . o c t s )isth s m a s + o c te a n p r to e ., 1 c n a ( 2 ea es 1 s) 2. C n etsalis o Uic d v lu sin as in c n in gth c r e p n in o vr t f n o e a e to tr g o ta in e or s o d g c a a tes hr c r . S a c e f rth f s o c r e c o s b tr gs r gf o p s nin e in e r h s o e ir t c ur n e f u s in ta tin r m o itio d x th s in th t in o e th mth d T emth dr tun th s r gin e o e tr g a v k s e e o . h e o e r s e tatin d x f s b tr ginth s uc s in o ifs b tr gisn t f u d I th in e u s in e o r e tr g r 1 u s in o o n . f e dx a g mn isn t po id d th mth db gn s a c in f o in e 0inth r u e t o r v e , e e o e i s e r h g r m dx e s uc s in . o r e tr g S a c e f rth la t o c r e c o s b tr gs r gf o p s nin e a d e r h s o e s c ur n e f u s in ta tin r m o itio d x n s a c in to adth b g n go th s in th t in o e th mth d T e e r h g wr e e in in f e tr g a v k s e e o . h mth dr tun th s r gin e o s b tr ginth s uc s in o if e o e r s e ta tin d x f u s in e o r e tr g r 1 s b tr gisn t f u d I th in e ag mn isn t po id d th mth d u s in o o n. f e dx r u e t o r v e , e e o b g ss ac in f o th e do th s uc s in . e in e r h g r m e n f e o r e tr g
11
Tokens
Individual words Separated by delimiters
Blink
<blink> blinking text </blink>
Fixed
<tt> monospaced text </tt>
Strike
<strike> strike out text </strike>
Subscript
<sub> subscript </sub>
Superscript
<sup> superscript </sup>
13
14
gtae) eDt( gtTDt( eUCae) gta( eDy) gtTDy) eUCa( gtuler) eFlYa( gtTFlYa( eUCuler) gtor( eHus) gtTHus) eUCor( gtilscns) eMlieod( gtTMlieod( eUCilScns) gtiue( eMnts) gtTMnts) eUCiue( gtot( eMnh) gtTMnh) eUCot( gteod( eScns) gtTScns) eUCeod( gtie) eTm( gtieoefst) eTmznOfe( s t a e v l) eDt( a s t T D t (v l ) eUCae a F .1 . ig 28 Mth d o th D t o je t e o s f e a e b c.
Rtun an me f o 0( u d y to6( aud y r pe e tin th d yo th we inlo a tim o U C e r s u br r m Sn a ) St r a ) e r s n g e a f e e k cl e r T , r s e tiv ly ep c e . Rtun t ey a a af u- ig n me inlo a tim o U C r s e tiv ly e r s h e r s o r d it u b r c l e r T , ep c e . Rtun an me f o 0to2 r pe e tin h ussn em n h i lo a t eo U C r s e tivly e r s u br r m 3 e r s n g o r i c id ig t n c l im r T , e p c e . Rtun an me f o 0to9 9r pe e tin th n me o m e o d i l c l tim o U C r s e tiv ly e r s u br r m 9 e r s n g e u b r f illis c n s n o a e r T , ep c e . T etim iss r dinh us m ue , s c n sa dm e o d . h e toe o r , in t s e o d n illis c n s Rtun an me f o 0to5 r pe e tin th m u sf rt etim inl c l tim o U C r s e tiv ly e r s u br r m 9 e r s n g e in te o h e oa e r T , ep c e . Rtun an me f o 0( a u r )to1 ( e e b r r pe e tin th mn i l c l tim o U C e r s u b r r m J n ay 1 Dc me) e r s n g e o th n o a e r T, r s e tiv ly ep c e . Rtun an me f o 0to5 r pe e tin th s c n sf rt etim inl c l tim o U C r s e tiv ly e r s u br r m 9 er sn g e eod o h e oa e r T , ep c e . Rtun t en me o m e o d b twe J n ay1 1 7 a dt etim inth D t o je t. e r s h u b r f illis c n s e e n a u r , 9 0 n h e e ae b c Rtun t ed f r n ei m u sb twe th c r e t tim o t el c l c mu ra dU C pe io s e r s h if ee c n in te e e n e ur n e n h o a o p te n T v u ly r k o na Ge n ic Ma T e( M) n w s r e w h e n im G T. S tsth d yo th mn ( to3 )inl c l tim o U C r s e tiv ly e e a f e o th 1 1 oa e r T , ep c e .
15
S ts th y a in lo a tim o U C re e tiv ly T e sec n a d th e e er c l e r T , sp c e . h o d n ird a u e ts re re n gth m n a d th d te a o tio a If a o tio a rg m n p se tin e o th n e a re p n l. n p n l a u e t is n t sp c d th c rre t v lu inth D t o je t is u d rg m n o e ifie , e u n a e e ae b c se .
S ts th h u inlo a tim o U C re e tiv ly T e sec n , th a d fo rth e e or c l e r T , sp c e . h o d ird n u s t o r ( h m s, m ) eHus , , s e n in illise s t T H u s h m s, m ) argum ntslrergum nt isthe mecified, thends andmlue inthes areeobject is eUCor( , , s anoptiona apreseeting not sp utes, seco current va condD toptional. If a u d se .
stilScns m ) eMlieod( s stTMlieod(m ) eUCilscns s s t i u e ( m s, m ) eMnts , s s t T M n t s m s, m ) eUCiue( , s stot(m d) eMnh , stTMnh m d) eUCot( , s t e o d ( s, m ) eScns s s t T S c n s s, m ) eUCeod( s
S ts th n m e o m e e u b r f illise o d in lo a tim o U C re e tiv ly cns c l e r T , sp c e . S ts th m u inlo a tim o U C re e tiv ly T e se o d a dth e e in te c l e r T , sp c e . h c n n ird a u e ts re re n gth se o d a dm rg m n p se tin e c n s n illise o d a o tio a If a c n s re p n l. n o tio a a u e t is n t sp c d th c rre t v lu inth D t o je t is p n l rg m n o e ifie , e u n a e e ae b c u d se . S ts th m n in lo a tim o U C re e tiv ly T e se o d a u e t e e o th c l e r T , sp c e . h c n rg m n re re n gth d te is o tio a If th o tio a a u e t is n t sp c d th p se tin e a p n l. e p n l rg m n o e ifie , e c rre t d te v lu in th D t o je t is u d u n a a e e ae b c se . S ts th se o d inlo a tim o U C re e tiv ly T e se o d a u e t e e cn c l e r T , sp c e . h c n rg m n re re n gth m p se tin e illise o d is o tio a If th a u e t is n t sp c d th c n s p n l. is rg m n o e ifie , e c rre t m u n illise o d v lu in th D t o je t is u d cn a e e ae b c se .
F . 1 .8 ig 2
M th d o th D t o je t. e os f e ae b c
16
St t e i e ae o isagm t t e u broe pe mi eod e h tmbsd nt r u e nm f l sd ilscns s n h e a l sne aur 117. i c Jnay , 90 Ru sa t i g er sn to ot e a adi e n f r s ei i t t e e r srn r p et i n f h dt n tmi a o pcfc oh t n e a e m cm t rsl cl .Frea p ,Sp m r1,20 a 3 2 2 M o p e oa o xme et b 3 01 t : : P i u e l e e 42 s r p sn d s0/ 3 1 5 7 2nh Ut d t t sad 3 9 1 er et a 9 / 1: : i t e ne S e n 1/ / e e 10 42 i a 00 1: 7 2n u p. 5 : i Er e 42 o Ru sa t i g er sn to ot e a adi e nh f r :1 Sp e r srn r p et i n f h dt n tmi t e o t n e a e m9e 20 1: 7 2 T 01 5 : U 42 C Ru sa t i g er sn to ot e a adi e n f r s ei i t t e e r srn r p et i n f h dt n tmi a o pcfc oh t n e a e m l cl ot e o pt r( o Sp 9 5 7 2 D20 i t e ne oa f h cm e M e 1 1: : E T 01 nh Ut d e u n 42 i S t s. t e) a Te i e n u bromi eod sne i n h Jnay ,17. h tmi nm f ilscns i c m i t aur 1 90 e l dg,
Mhd ot e ae b c e os f h Dt oj t t e.
17
18
19
20
21
22
Dp e tn si co r i Rsei h l o Be b i e t s g e t v fe on c tn t t i e u t oajt u h nr f a h l o s r r u e e tehi, tnei e r;t rs e s s gl. u e e ut t f ow r h na r r s ve) aO lf u( Rse u ut Be b i row e t v t ih ones ut rs tn a rfe l o t t; hi, u hl r e e oa j c ee e r r fe e sl tn s u a. on t t d lo F2 i1 g1 Be b ms . . 0 oa jce . e h o
M e td h o tr( oi) Sn tg
23
M e td h o tr( oi) Sn tg
24
25
26
27
1 2 3 4 5 6 7 8 9
<?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <!-- Fig. 12.13: window.html <!-- Using the Window Object --> -->
10 <title>Using the Window Object</title> 11 <!-12 <script type = "text/javascript"> 13 14 15 16 17 18 19 20 21 22 23 24 25 function createChildWindow() { // these variables all contain either "yes" or "no" // to enable or disable a feature in the child window var toolBar // specify if toolbar will appear in child window var menuBar; // specify if menubar will appear in child window var location; // specify if address bar will appear in child window var scrollBars; // specify if scrollbars will appear in child window var status; // specify if status bar will appear in child window var resizable; // specify if the child window will be resizable
window.html 1 of 7
28
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 // determine whether the Scroll Bar checkbox is checked if ( scrollBarsCheckBox.checked ) scrollBars = "yes"; else scrollBars = "no"; // determine whether the Menu Bar checkbox is checked if ( menuBarCheckBox.checked ) menuBar = "yes"; else menuBar = "no"; // determine whether the Tool Bar checkbox is checked if ( toolBarCheckBox.checked ) toolBar = "yes"; else toolBar = "no";
// determine whether the Address Bar checkbox is checked if ( locationCheckBox.checked ) location = "yes"; else location = "no";
window.html 2 of 7
29
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
// determine whether the Status Bar checkbox is checked if ( statusCheckBox.checked ) status = "yes"; else status = "no"; // determine whether the Resizable checkbox is checked if ( resizableCheckBox.checked ) resizable = "yes"; else resizable = "no";
childWindow = window.open( "", "", "resizable = " + resizable + ", toolbar = " + toolBar + ", menubar = " + menuBar + ", scrollbars = " + scrollBars ); // disable buttons closeButton.disabled = false; modifyButton.disabled = false; getURLButton.disabled = false; setURLButton.disabled = false; } // end function createChildWindow ", status = " + status + ", location = " + location +
window.html 3 of 7
30
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
// insert text from the textbox into the child window function modifyChildWindow() { if ( childWindow.closed ) alert( "You attempted to interact with a closed window" ); else childWindow.document.write( textForChild.value ); } // end function modifyChildWindow // close the child window function closeChildWindow() { if ( childWindow.closed ) else childWindow.close(); closeButton.disabled = true; modifyButton.disabled = true; getURLButton.disabled = true; setURLButton.disabled = true; } // end function closeChildWindow
window.html 4 of 7
31
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
// copy the URL of the child window into the parent windows myChildURL function getChildWindowURL() { if ( childWindow.closed ) alert( "You attempted to interact with a closed window" ); else myChildURL.value = childWindow.location; } // end function getChildWindowURL // set the URL of the child window to the URL // in the parent windows myChildURL function setChildWindowURL() { if ( childWindow.closed ) else childWindow.location = myChildURL.value; } // end function setChildWindowURL //-->
window.html 5 of 7
118 </script> 119 120 </head> 121 122 <body> 123 <h1>Hello, This is the main window</h1>
32
124 <p>Please check the features to enable for the child window<br/> 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 <p>Please enter the text that you would like to display 145 146 147 in the child window<br/> <input id = "textForChild" type = "text" value = "<h1> Hello, I am a child window</h1> <br\>"/> <input id = "toolBarCheckBox" type = "checkbox" value = "" checked = "checked" /> <label>Tool Bar</label> <input id = "menuBarCheckBox" type = "checkbox" value = "" checked = "checked" /> <label>Menu Bar</label> <input id = "locationCheckBox" type = "checkbox" value = "" checked = "checked" /> <label>Address Bar</label><br/> <input id = "scrollBarsCheckBox" type = "checkbox" value = "" checked = "checked" /> <label>Scroll Bars</label> checked = "checked" /> <label>Status Bar</label> <input id = "resizableCheckBox" type = "checkbox" value = "" checked = "checked" /> <label>Resizable</label><br/></p>
window.html 6 of 7
33
18 4 19 4 10 5 11 5 12 5 13 5 14 5
< n u i =" r a e u t n t p =" u t n ipt d cetBto" ye bto" v l e =" r a e C i d W n o "o c i k = " r a e h l W n o ( "/ au Cet hl idw nlc cetCididw) > < n u i =" o i y u t n t p =" u t n v l e =" o i y C i d W n o " ipt d mdfBto" ye bto" au Mdf hl idw o c i k =" o i y h l W n o ( "d s b e =" i a l d / nlc mdfCididw) iald dsbe"> < n u i =" l s B t o "t p =" u t n v l e =" l s C i d W n o " ipt d coeutn ye bto" au Coe hl idw oc i k="l s Ci di dw ) ds be ="i al d/< p nlc coehlWno(" iald dsbe">/>
1 5 < > h o h r w n o ' U L i :< r > 5 pTe te idws R s b/ 16 5 17 5 18 5 19 5 10 6 11 6 12<bd> 6 /oy 13<hm> 6 /tl < n u i =" y h l U L t p =" e t v l e =" // ipt d mCidR" ye tx" au ."> < n u i =" e U L u t n t p =" u t n v l e =" e C i d U L ipt d stRBto" ye bto" au St hl R" o c i k =" e C i d i d w R ( "d s b e =" i a l d / nlc sthlWnoUL) iald dsbe"> < n u i =" e U L u t n t p =" u t n v l e =" e U L F o C i d ipt d gtRBto" ye bto" au Gt R rm hl" o c i k =" e C i d i d w R ( "d s b e =" i a l d / < p nlc gthlWnoUL) iald dsbe">/>
window.html 7 of 7
34
35
36
37
38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?xml version = "1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" > <!-- Fig. 12.15: cookie.html --> <!-- Using Cookies -->
<html xmlns = "http://www.w3.org/1999/xhtml" > <head> <title>Using Cookies</title> <script type = "text/javascript"> <!--
var now = new Date(); // current date and time var name;
cookie.html 1 of 4
if ( hour < 12 ) // determine whether it is morning document.write( "<h1>Good Morning, " ); else { hour = hour - 12; // convert from 24 hour clock to PM time
39
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 } }
// determine whether it is afternoon or evening if ( hour < 6 ) document.write( "<h1>Good Afternoon, " ); else document.write( "<h1>Good Evening, " );
// determine whether there is a cookie if ( document.cookie ) { // convert escape characters in the cookie string to their // english notation var myCookie = unescape( document.cookie );
// split the cookie into tokens using = as delimiter var cookieTokens = myCookie.split( "=" );
cookie.html 2 of 4
// set name to the part of the cookie that follows the = sign name = cookieTokens[ 1 ]; else { // if there was no cookie then ask the user to input a name name = window.prompt( "Please enter your name", "GalAnt" );
40
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 } }
// escape special characters in the name string // and add name to the cookie document.cookie = "name=" + escape( name );
document.writeln( name + ", welcome to JavaScript programming! </h1>" ); document.writeln( "<a href= \" JavaScript:wrongPerson() \" > " + "Click here if you are not " + name + "</a>" ); // reset the document's cookie if wrong person function wrongPerson() { // reset the cookie
document.cookie= "name=null;" +
cookie.html 3 of 4
" expires=Thu, 01-Jan-95 00:00:01 GMT"; // after removing the cookie reload the page to get a new name location.reload();
41
7 4 7 5 7 6
7< m 7/ l h> t
cookie.html 4 of 4
42
43
Objectives
In this lesson, you will learn:
To use the Dynamic HTML Object Model and scripting to create dynamic Web pages. To understand the Dynamic HTML object hierarchy. To use the all and children collections to enumerate all of the XHTML elements of a Web page. To use dynamic styles and dynamic positioning. To use the frames collection to access objects in a separate frame on your Web page. To use the navigator object to determine which browser is being used to access your page.
44
13.1 Introduction
Dynamic HTML Object Model
Allows Web authors to control the presentation of their pages Gives them access to all the elements on their pages
Web page
Elements, forms, frames, tables Represented in an object hierarchy
Scripting
Retrieve and modify properties and attributes
Referring to text
http://www.irt.org/script/1370.htm
45
document
document
links
plugins scripts
collection
styleSheets
Fig. 13.10
46
47
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?xml version = "1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- Fig. 13.1: reference.html -->
<!-- Object Model Introduction --> <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Object Model</title> <script type = "text/javascript"> <!-function start() { alert( pText.innerText ); pText.innerText = "Thanks for coming."; } // --> </script> </head>
<yl = t( b oa "r" o nd st> d o a) <d"xWotuea < p =T"le oWp! > i pt emorbg / e>c ep <d /y b> o
2 3 2 4 2 5 2 6
2< m 7/ l h> t
48
children
Specific element contains that elements child elements
49
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2 5 } // --> <r> /i sp ct pText.innerHTML += elements; alert( elements ); function start() { for ( var loop = 0; loop < document.all.length; ++loop ) elements += "<br />" + document.all[ loop ].tagName; <script type = "text/javascript"> <!-var elements = ""; <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>Object Model</title> <!-- Fig 13.2: all.html -->
Outline
all.html (1 of 2)
2 6 2 7 2 8 2 9 3 0
<a /d h> e <yl =t( b oa "r" o nd st> d o a) <d"xEe ohWp:> p =T"etniea < i ptln e>ms t sbg/ ep <d /y b> o
3< m 1/ l h> t
50
13 14 15 16 17 18 19 20
2 2 21 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8
<!vreeet ="u>; a lmns <l" fnto cid ojc ) ucin hl( bet { vrlo =0 a op ; eeet + "l> +ojc.aNm +"u>; lmns = <i" bettgae <l"
fr(lo =0 lo <ojc.hlrnlnt;lo+ ) o op ; op betcide.egh op+ { i (ojc.hlrn lo ]cide.egh) f betcide[ op .hlrnlnt cid ojc.hlrn lo ]) hl( betcide[ op ; es le eeet + "l> + lmns = <i" o j c . h l r n l o ] t g a e+ betcide[ op .aNm "/i" <l>; } eeet + "/l"+"/i" lmns = <u> <l>; } / -> / <srp> /cit <ha> /ed
Outline
<oyola ="hl(dcmn.l[4]) bd nod cid ouetal ; mDslyotrTL+ eeet; yipa.ueHM = lmns mDslyotrTL+ /l" yipa.ueHM = <u>;> <>ecm t or<togWb/tog pg!/> pWloe o u srn>e<srn> ae<p < i ="yipa" pd mDsly> Eeet o ti Wbpg: lmns n hs e ae <p />
3 9 4 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7
51
52
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 4 5 <!-- Fig. 13.4: dynamicstyle.html --> 6 <!-- Dynamic Styles 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 } // --> </script> </head> <script type = "text/javascript"> <!-function start() { var inputColor = prompt( "Enter a color name for the " + "background of this page", "" ); document.body.style.backgroundColor = inputColor; <head> <title>Object Model</title> --> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Outline
2 4 2 5 2 6 2 7 <yl =t( b oa "r" o nd st> d o a) <emorbt/ ple oWs!> >c tuei< Wo ep <d /y b> o
2< m 8/ l h> t
53
4 5 <!-- Fig. 13.5: dynamicstyle2.html --> 6 <!-- More Dynamic Styles 7 8 <html xmlns = "http://www.w3.org/1999/xhtml"> 9 10 11 12 13 14 15 16 17 18 19 20 2 1 </style> .smallText { font-size: .75em } .bigText { font-size: 3em; font-weight: bold } <style type = "text/css"> <head> <title>Object Model</title> -->
Outline
<cittp ="etjvsrp" srp ye tx/aacit> <!fnto sat) ucin tr( { vriptls =pop( a nuCas rmt "ne acasaefrtetx " + Etr lsNm o h et "bgeto salet" " ) (iTx r mlTx), " ; petcasae=iptls; Tx.lsNm nuCas } / -> / <srp> /cit <ha> /ed <oyola ="tr(" bd nod sat)> < i ="Tx"Wloet orWbst!/> p d pet>ecm o u e ie<p <bd> /oy
2 2 2 3 2 4 2 5 2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 3 4 3 5 3 6
3 <hm> 7 /tl
54
55
Outline
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
function run() { count += speed; if ( ( count % 200 ) == 0 ) { speed *= -1; direction = !direction; pText.style.color = ( speed < 0 ) ? "red" : "blue" ; firstLine = ( speed < 0 ) ? "Text shrinking" : "Text growing"; pText.style.fontFamily = fontStyle[ ++fontStylecount % 3 ]; } pText.style.fontSize = count / 3; pText.style.left = count; pText.innerHTML = firstLine + "<br /> Font size: " + count + "px"; } // --> </script> </head>
56
57
1 <?xml version = "1.0"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 3 4 5 <!-- Fig. 13.8: top.html --> 6 <!-- Cross-frame scripting --> 7 8 <html xmlns = "http://www.w3.org/1999/xhtml" > 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 } // --> </script> </head> <script type = "text/javascript"> <!-function start() { var text = prompt( "What is your name?", "" ); parent.frames( "lower" ).document.write( "<h1>Hello, " + text + "</h1>" ); <head> <title>The frames collection</title> "http://www.w3.org/TR/xhtml1/DTD/xhtml1 -strict.dtd">
2 <DCYEhm PBI "/WC/T XTL10Faee !OTP tl ULC -/3/DD HM . rms 3 4 5 <- Fg 1.:idxhm !- i. 37 ne.tl 7 8 < t l x l s =" t p / w w w . r / 9 9 x t l> hm mn ht:/w.3og19/hm" 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 <hm> 8 /tl
2 4 2 5 2 6 <yl =t( b oa "r" o nd st> d o a) <Csaspgh hr-mct!1 1oferi<> >sr in/ <d /y b> o
Outline
" t p / w w w . r / R x t l / T / h m 1f a e e . h t : / w . 3 o g T / h m 1 D D x t l- r m s t -> -
<ed ha> <il>rmscleto<tte tteFae olcin/il> <ha> /ed <rmstrw ="0,*> faee os 10 " <rm sc="o.tl nm ="pe"/ fae r tphm" ae upr > <rm sc=" nm ="oe"/ fae r " ae lwr > <faee> /rmst
2< m 7/ l h> t
58
59
Contains information about the Web browser Allows Web authors to determine what browser the user is using
60
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
2 6 2 7 2 8 2 9 3 0 3 1 3 2 3 3 < d o o =s r ) byna "a(> o ld tt" <Ricnyrrs tt arrtpe per tgo bwroh poiea, >dei u oe e ppa g pa wt.p ls a.<> ee i./ <o> /d by
<html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title>The navigator Object</title> <script type = "text/javascript"> <!-function start() { if (navigator.appName=="Microsoft Internet Explorer") { if ( navigator.appVersion.substring( 1, 0 ) >= "4" ) document.location = "newIEversion.html"; else document.location = "oldIEversion.html"; } else document.location = "NSversion.html"; }
//> <cp /rt si> <e> /a hd
Outline
navigat or.html (1 of 2)
3 <t> 4 /m hl
61
document
document
links
plugins scripts
collection
styleSheets
Fig. 13.10
62
dcmn ouet
bd oy hsoy itr
nvgtr aiao
F . 1 .1 ig 3 1
63
acos nhr
apes plt ebd mes frs om fae rms iae mgs lns ik
F . 1 .1 ig 3 1
O je tsinth In rn t E p re 6O je t M d l. b c e te e x lo r b c oe
64
Ot ro t n eit n b olc Dp jc c i e l o s i e co r
pi ln us g sp ct rs i
F3 i. .1 Ot i teet x r 6 jc o. g 1 1 b s h tr E e Ot d jcn I n p r b M e ne l o e e l
65
Helpful references
http://www.devguru.com/Technologies/ecmascript/quickref/js_objects.html http://www.w3schools.com/js/js_obj_htmldom.asp
66