• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Q&A

Q1:If this is a book about JavaScript 1.5, why didn't we specify the JavaScript version number in the beginning <script> tag?
A1: Since this script doesn't use any features specific to JavaScript 1.5, it's best to include the lowest possible version number. If we used the tag <script LANGUAGE="JavaScript1.5">, the script would only run on Netscape 6.0 or later and Internet Explorer 5.5 or later. Since this script requires only JavaScript 1.0's basic features, we used the tag <script LANGUAGE="JavaScript">. With this tag, the script will run on Netscape 2.0, MSIE 3.0, and other JavaScript-compatible browsers.
Q2:When I try to run my script, Netscape displays the actual script in the browser window instead of executing it. What did I do wrong?
A2: This is most likely caused by one of three errors. First, you may be missing the beginning or ending <script> tags. Check them, and verify that the first reads <script LANGUAGE="JavaScript">. Second, your file may have been saved with a .txt extension, causing Netscape to treat it as a text file. Rename it to .htm or .html to fix the problem. Third, make sure your browser supports JavaScript, and that it is not disabled in the Preferences dialog.
Q3:Why are the <b> and <p> tags allowed in the statements to print the time? I thought HTML tags weren't allowed within the <script> tags.
A3: Since this particular tag is inside quotation marks, it's considered a valid part of the script. The script's output, including any HTML tags, is interpreted and displayed by the browser. You can use other HTML tags within quotation marks to add formatting, such as the <font> tags we added for the large clock display.
Q4:I can imagine a large script making a mess of my beautifully formatted HTML documents. Can I move the script to a separate file?
A4: Yes. Create a file with a .js extension and place the script statements (not including the <script> tags) in this file. Leave the <script> tags in the HTML file and modify the first tag to refer to the file, such as <script LANGUAGE="JavaScript" SRC="filename.js">. This feature works only for JavaScript 1.1 and later.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint