Previous Example-|-Next Chapter's Examples-|-Return to Chapter Listing

Example 11.7:
Object Properties are Sometimes Strings

When you opened this document, JavaScript applied the lastIndexOf string method to the navigator.appVersion property (which is a string). This method checked to find out what type of browser you are using (either Windows, or UNIX or Mac), then tells the script which kind of line break to use when placing text into the textarea.

This is the script we used in the HEAD: <SCRIPT LANGUAGE="JAVASCRIPT"> <!-- var nl=null if (navigator.appVersion.lastIndexOf('Win') != -1) { nl = "\r\n" } else { if (navigator.appVersion.lastIndexOf('Mac') != -1) { nl = "\r" } else { nl = "\n" } } function placeText() { var text1=prompt("Type over this line if you wish", "This is the default first line of text") var text2=prompt("Type over this line if you wish", "This is the default second line of text") var text3=prompt("Type over this line if you wish", "This is the default third line of text") var text4=prompt("Type over this line if you wish", "This is the default fourth line of text") var text5=prompt("Type over this line if you wish", "This is the default fifth line of text") document.text.codes.value= text1 + nl + text2 + nl + text3 + nl + text4 + nl + text5 } //--> </SCRIPT> </HEAD> <BODY onload=placeText()> This is the textarea we created: <FORM NAME="text"> <TEXTAREA NAME="codes" ROWS=10 COLS=40></TEXTAREA> </FORM>
Previous Example-|-Next Chapters Examples-|-Return to Chapter Listing