10.6 Inserting JavaScript

     

As Chapter 12 makes clear, Dreamweaver's Behaviors (prewritten JavaScript programs) let you add exciting interactive effects ”mouse rollovers, pop-up windows , animated layers , and so on ”with very little effort. But they can't do everything: When you, the native JavaScript speaker, need to wade into the depths of JavaScript programming yourself, you'll find two entrances within Dreamweaver.

The most straightforward approach, especially if you're already familiar with Java- Script programming, is to simply switch into Code view (Ctrl+` [Option-`]) and type away. Or, if you prefer, you can use Dreamweaver's Insert Script window to add your JavaScript code (see Figure 10-13).

Unlike the Code view, the Insert Script window doesn't respond to the Tab key; if you're accustomed to indenting your code, you'll need to use spaces. You can also insert noscript information ”text that appears if the Web browser doesn't understand JavaScript (noscript only works, however, if you're adding a script somewhere in the <body> of the page, not in the <head>.
figs/10_13.jpg

To do so, click in either the head or body section of the page, and then choose Insert HTML Script Objects Script (alternatively you can access this option from the Script menu on the HTML tab of the Insert bar.) In the Insert Script window (Figure 10-13), choose a language from the menu: JavaScript, JavaScript1.1, JavaScript1.2, or VBScript. (The JavaScript option works with all browsers that understand JavaScript, while JavaScript 1.2 only works in 4+ version browsers. VBScript, on the other hand, works only in the Windows version of Internet Explorer.)

Just type your script into the Content section (no need to include <script> tags, as Dreamweaver handles that part) and then click OK. If you inserted the script in the body of the document, you'll see a small gold icon (indicating an invisible element on the page) to mark its location.

NOTE

The JavaScript debugger that debuted in Dreamweaver 4 has been retired . Sorry.

You can edit your script in Code view, of course. In Design view, select the script icon and then click Edit in the Property inspector.

Dreamweaver also lets you open and work on external JavaScript files (.js files) right in Code view. The program doesn't try to interpret the file as an HTML page; it won't attempt to make any of the changes described in Section 10.1.1. You can just use the builtin text-editing capabilities of Code view to write your JavaScript programs.

JavaScript programming is no walk in the park. While it's certainly easier to learn than full-featured languages like Java or C++, it can still be challenging. If you want to get your feet wet, here's a great resource for basic tutorials and information on JavaScript: www.Webmonkey.com/programming/javascript/ .




Dreamweaver MX 2004. The Missing Manual
Dreamweaver MX 2004: The Missing Manual
ISBN: 0596006314
EAN: 2147483647
Year: 2003
Pages: 191

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net