In the example, the document contains several script blocks. The script source is extracted and formatted with an escape() function and line breaks are reinserted by means of the String.split() and Array.join() methods.
<HTML> <HEAD></HEAD> <BODY> <TABLE BORDER=1> <TH>Index</TH> <TH>ID</TH> <TH>Text</TH> <SCRIPT ID="ONE"> block1 = "ONE"; </SCRIPT> <SCRIPT ID="TWO"> block2 = "TWO"; </SCRIPT> <SCRIPT ID="THREE">block3 = "THREE";</SCRIPT> <SCRIPT ID="FOUR"> block4 = "FOUR"; myLength = document.scripts.length; for (myEnumerator=0; myEnumerator<myLength; myEnumerator++ ) { mySourceText = escape(document.scripts[myEnumerator].text); myArray = mySourceText.split("%0D"); document.write("<TR><TD>"); document.write(myEnumerator); document.write("</TD><TD>"); document.write(document.scripts[myEnumerator].id); document.write("</TD><TD>"); document.write(myArray.join("%0D<BR>")); document.write("</TD></TR>"); } </SCRIPT> </TABLE> </BODY> </HTML>
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
length | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
item() | ![]() | 3.0 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
Prev | Home | Next |
<SCRIPT> | Up | ScriptArray.item() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |