in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

Javascript for dummies 4th edition - Veer E.V

Veer E.V Javascript for dummies 4th edition - Wiley publishing , 2004. - 387 p.
ISBN: 0-7645-7659-3
Download (direct link): javascriptfordummies2005.pdf
Previous << 1 .. 11 12 13 14 15 16 < 17 > 18 19 20 21 22 23 .. 118 >> Next

32 Part I: Building Killer Web Pages for Fun and Profit
that they need to use a JavaScript-enabled Web browser to get the most from your Web page:
You must be running a JavaScript-enabled Web browser, such as the latest version of Microsoft Internet Explorer or Netscape Navigator, to get the most from this Web page.
Testing Your Script
When you have an HTML file that contains embedded JavaScript code, as shown previously in Listing 2-3, you’re ready to test your JavaScript application! (This is the really fun part.)
To test a JavaScript application, all you need to do is load the JavaScript-containing HTML file into a JavaScript-supporting Web browser. Figure 2-3 shows you how the code in Listing 2-3 looks when it’s loaded into the Netscape 7.1 browser.
Figure 2-3:
The date-and-time-stamp application as it appears in Netscape 7.1.
Chapter 2: Writing Your Very First Script
Note: You can find a fancier version of the date-and-time-stamp application in Chapter 3.
If you load the code in Listing 2-3 in your browser and see a Web page similar to the one shown in Figure 2-3, congratulations! You’ve just successfully tested your very first JavaScript script.
If you don’t see a Web page similar to the one in Figure 2-3, however, don’t despair. Chances are good that the problem is due to one of the following situations:
^ The correct HTML file isn’t loaded. If you created your HTML file from scratch, you might have inadvertently mistyped a statement or otherwise introduced a bug. No problem; you can fix the bug later. (Chapter 17 is packed with tips for debugging your scripts.) For now, try loading the bug-free list0203.htm file from the companion CD.
^ You’re not using a JavaScript-enabled browser. Make sure that you’re using Microsoft Internet Explorer 6.0 (or higher) or Netscape Navigator 7.1 (or higher).
^ JavaScript support is turned off in your browser. Netscape Navigator and Microsoft Internet Explorer both provide ways to turn off JavaScript support. When you turn off JavaScript support in your browser and then load a JavaScript-containing Web page, your browser ignores all the JavaScript code. It’s as if it didn’t exist!
To make sure that JavaScript support is turned on, do the following:
^ If you’re using Netscape Navigator 7.x, choose EditOPreferences and double-click the Advanced menu option to display the Scripts & Plugins menu selection. Click the Scripts & Plugins men selection and make sure that the Enable JavaScript for Navigator check box is selected.
^ If you’re using Internet Explorer 6.x, choose ToolsOInternet OptionsO Security. Then select the Internet Web Content Zone, click the Custom Level button, and scroll down until you find the Active Scripting category. Finally, ensure that the Enable option (right under the Active Scripting option) is selected.
34 Part I: Building Killer Web Pages for Fun and Profit
Chapter З
JavaScript Language Basics
In This Chapter
^ Taking a look at JavaScript syntax
^ Putting together JavaScript expressions and statements ^ Practicing JavaScript language basics with the browser-detection script ^ Understanding conditionals ^ Exploring functions
Лlthough JavaScript is an awfully powerful language, the way you use it can be boiled down to just two major concepts: syntax and the JavaScript object model (also called the document object model).
Syntax refers to the rules that you must follow to write JavaScript code. Not many syntax rules exist, but you do need to understand them — just as you need to understand and follow the rules of English syntax to write a sentence that English-speaking folks can understand.
The document object model (DOM) refers to the Web page components, or objects, that you can access and manipulate by using JavaScript. In the same way that you need to have a vocabulary of English words before you can write a story in English, you need to be somewhat familiar with the DOM before you can write your own JavaScript scripts. (I devote Chapter 4 to the DOM.) This chapter arms you with the syntax knowledge that you need to write your own scripts!
JavaScript Syntax
The rules and regulations that govern how humans can communicate with the JavaScript interpreter — that piece of the Web browser that understands and executes JavaScript code — is called the JavaScript syntax. Although you might feel a little overwhelmed (especially at first!) with all the technicalities
Part I: Building Killer Web Pages for Fun and Profit
of JavaScript syntax, you can focus on just these few things, which are the building blocks of your code:
^ Comments: Comments are human-readable (as opposed to JavaScript-interpreter-readable) descriptions you can add to your script to make your script easier to understand and maintain.
^ Conditionals: Conditionals are logical constructs that you can add to your script to decide whether a particular condition is true or false at runtime. The most basic conditional is i f-else.
Previous << 1 .. 11 12 13 14 15 16 < 17 > 18 19 20 21 22 23 .. 118 >> Next