« Home « Kết quả tìm kiếm

Javascript bible_ Chapter 3


Tóm tắt Xem thử

- Your First.
- Because of differences in the way various personal computing operating systems behave, I present details of environments for two popular variants: Windows 95 and the MacOS.
- For the most part, your JavaScript authoring experience will be the same regardless of the operating system platform you use — including UNIX.
- If you’re running another version of Navigator, don’t fret if every pixel doesn’t match with the illustrations in this book..
- The best way to learn JavaScript is to type the HTML and scripting code into documents in a text editor.
- guidelines for choosing a text editor in the next section..
- While learning JavaScript, you may be better off using a simple text editor rather than a high- powered word processor with HTML extensions..
- Choosing a text editor.
- In the case of Windows, any program that not only saves the file as text by default but also lets you set the extension to .htm or .html will prevent a great deal of problems.
- If you were to use Microsoft Word, for example, the.
- To save the file initially as a text or .html extension file requires mucking around in the Save As dialog box.
- For the MacOS, SimpleText is also fine, though the lack of a search-and-replace function may get in the way when you start managing your Web site pages.
- This product includes a nice text editor window for entering scripts..
- The other component required for learning JavaScript is the browser.
- You don’t have to be connected to the Internet to test your scripts in the browser.
- This means you can learn JavaScript and create cool-scripted Web pages with a laptop computer, even on a boat in the middle of an ocean..
- The only requirement for the browser is that it be compatible with the current release of JavaScript.
- Microsoft’s Internet Explorer 4 supports most of the core language of Navigator 4, but you’ll still find occasional incompatibilities..
- To make the job of testing your scripts easier, make sure that you have enough free memory in your computer to let both your text editor and browser run simultaneously.
- Switch to the browser..
- Do one of the following: If this is a new document, open the file via the browser’s Open menu.
- Or if the document is already loaded, reload the file into the browser..
- In fact, you may find them easier to work with if you adjust the size and location of each window so both windows are as large as they can be while still enabling you to click on a sliver of the other’s window.
- In practice, however, the Windows Alt+Tab task-switching keyboard shortcut makes the job of the save-switch-reload steps outlined earlier a snap.
- If you’re running Windows 95 and also using a Windows 95-compatible text editor (which more than likely has a Ctrl+S file-saving keyboard shortcut) and the Netscape Navigator 4 browser (which has a Ctrl+R reload keyboard shortcut), you can effect the save-switch-reload from the keyboard, all with the left hand: Ctrl+S (save the source file).
- As long as you keep switching between the browser and text editor via Alt+Tab task switching, either program is always just an Alt+Tab away..
- If you expand the windows of your text editor and browser to full screen, you have to use the rather inconvenient Application menu (right-hand icon of the menu bar) to switch between the programs.
- A better method is to adjust the size and location of the windows of both programs so they overlap, while allowing a portion of the inactive window to remain visible ( Figure 3-2).
- Click in the browser window..
- To return to editing the source file, click on any exposed part of the text editor’s window..
- For the sake of simplicity, the kind of script you will be looking at is the kind that runs automatically when the browser opens the HTML page.
- Although all scripting and browsing work done here is offline, the behavior of the page would be identical if you placed the source file on a server and someone were to access it via the Web..
- Figure 3-3 shows the page as it appears in the browser after you’re finished (the exact wording differs slightly if you’re running your browser on an operating system platform other than Windows 95 or NT, or if you’re using a browser other than Netscape Navigator).
- The part of the page that is defined in regular HTML contains nothing more than an <H1>- level header with a horizontal rule under it.
- Below the rule, the script displays plain body text that combines static text with information about the browser you used to load the document.
- The script writes a stream of HTML information to the browser, including a tag to render a portion of the information in boldface.
- Launch your text editor and browser.
- If the browser’s Stop button is active, click it to halt any network searching it may be trying to do..
- You may receive a dialog box message indicating that the URL for your browser’s home page (usually the home page of the browser’s publisher — unless you’ve changed the settings) is unavailable.
- You want the browser open, but you shouldn’t be connected to your ISP.
- If you’re automatically connected via a local area network in your office or school, that’s also fine, but you won’t be needing the network connection for now.
- Activate your text editor and create a new blank document..
- Type the script into the window exactly as shown in Listing 3-1..
- <H1>Let's Script...</H1>.
- <SCRIPT LANGUAGE="JavaScript">.
- document.write("This browser is version ".
- navigator.appVersion) document.write(".
- navigator.appName + "</B>.").
- </SCRIPT>.
- If you typed all lines as directed, the document in the browser window should look like the one in Figure 3-3 (with minor differences for your computer’s operating system and browser version).
- If the browser indicates that a mistake exists somewhere as the document loads, don’t do anything about it for now (click the OK button in the script error dialog box).
- of the entire document so you understand some of the finer points of what the script is doing..
- Examining the Script.
- You do not need to memorize any of the commands or syntax that I discuss in this section.
- Instead, relax and watch how the lines of the script become what you see in the browser.
- In Listing 3-1, all of the lines up to the <SCRIPT>.
- The <SCRIPT>.
- Any time you include JavaScript verbiage in an HTML document, you must enclose those lines inside a <SCRIPT>...</SCRIPT>.
- These tags alert the browser program to begin interpreting all the text between these tags as a script..
- advantage of these script tags, you must specify the precise name of the language in which the enclosed code is written.
- Therefore, when the browser receives this signal that your script uses the JavaScript language, it uses its built-in JavaScript interpreter to handle the code.
- You can find parallels to this setup in real life: If you have a French interpreter at your side, you need to know that the person with whom you’re conversing also knows French.
- If you encounter someone from Russia, the French interpreter won’t be able to help you.
- Your HTML tags (including the <SCRIPT>.
- tag) can be in the case of your choice, but everything in JavaScript is case- sensitive.
- The next line after the <SCRIPT>.
- In other words, the browser begins interpreting the next line after a comment start tag.
- If you want to put a comment inside JavaScript code, the comment must start with a double slash.
- In fact, the latter case appears near the end of the script.
- Such a browser would blow past the <SCRIPT>.
- But it would treat a line of script as regular text to be displayed in the page.
- By enclosing script lines between HTML comment tags, most older browsers won’t display the script lines.
- Figure 3-4 shows the results of your first script when viewed in a now-obsolete version of the America Online Web browser (version 2.5 for.
- Here, an old America Online browser shows part of the script anyway..
- Notice that the comment lines that shield older browsers from your scripts go inside the <SCRIPT>...</SCRIPT>.
- Do not put these comment lines above the <SCRIPT>.
- tag or below the </SCRIPT>.
- One more issue about the script-hiding comment lines in this book.
- But as you can see in the full-fledged application examples on the CD-ROM (in the folder named Bonus Applications Chapters), the comment lines are where they should be.
- Both script lines use one of the possible actions a script can ask a document to perform ( document.write.
- meaning display text in the current document).
- Whenever you ask an object (a document in this case) to perform a task for you, the name of the task is always followed by a set of parentheses.
- In some cases — the write() task, for example — JavaScript needs to know what information it should act on.
- That information (called a parameter) goes inside parentheses after the name of the task.
- Thus, if you want to write the name of the first U.S.
- document.write(“George Washington”).
- The line of text that the script writes starts with some static text ( “This browser is version.
- more evaluated text (the name of the browser application), and ends with an HTML closing tag and the sentence’s period ( “</B>.
- Neither JavaScript nor the + symbol knows anything about words and spaces, so the script is responsible for making sure that the proper spaces are passed along as part of the parameters..
- Notice, therefore, that an extra space exists after the word “version” in the first document.write() parameter, as well as spaces on both sides of “of” in the second document.write() parameter..
- To fetch the information about the browser version and name for your.
- If you’re searching for some English to mentally assign to this scheme as you read it, start from the right side and call the right item a property “of” the left side: the appVersion property of the navigator object.
- This dot syntax looks a great deal like the document.write() task, but a property name does not have parentheses after it.
- In any case, the reference to the property in the script tells JavaScript to insert the value of that property in the spot where the call is made..
- For your first attempt at the script, JavaScript substitutes the internal information about the browser as part of the text string that gets written to the document..
- If you encountered an error in your first attempt at loading this document into your browser, go back to the text editor and check the lines of the script section against Listing 3-1, looking carefully at each line in light of the explanations.
- To see how dynamic the script in script1.htm is, go back into the text editor and replace the word “browser” with “client software.” Save, switch, and reload to see.
- text for the quoted text in the document.write() statement.
- Or, add more text with additional document.write() statements.
- write() are HTML text, so you can even write a “ <BR>

Xem thử không khả dụng, vui lòng xem tại trang nguồn
hoặc xem Tóm tắt