Calling JavaScript

Team-Fly    

Macromedia® DreamWeaver® MX Unleashed
By Matthew Pizzi, Zak Ruvalcaba
Table of Contents
Chapter 19.  Behaviors


This behavior enables you to insert simple JavaScript or to call and communicate with JavaScript functions. Of course, this is no good if you don't know JavaScript, but it can be helpful if you pick some JavaScript code and you're sure where to place it within the HTML.

In the previous example, you created a pop-up window. A common element you find in most pop-up windows is a close button. To create one of these Close buttons, you must insert the JavaScript yourself because no behavior is built in to Dreamweaver to deal with this.

Creating a Close button is simple. Follow these steps to learn how to make your own Close button:

  1. Open the pop_out.html document that you created in the previous example.

  2. Create a Close button graphic in your favorite image-editing program, or visit the companion Web site at http://www.dreamweavermxunleashed.com and download close.gif.

  3. In the pop_out.html document, place a blinking cursor where you want the Close button to appear. Choose Insert, Image and navigate your hard drive to find the Close button graphic. When you find it, choose OK.

  4. With the graphic in the document, select it, and in the Behaviors panel click the Add Behavior (+) button. In the drop-down menu choose Call JavaScript. This opens the Call JavaScript dialog box as shown in Figure 19.8.

    Figure 19.8. The Call JavaScript dialog box has a text field in which you can type JavaScript code.

    graphics/19fig08.jpg

  5. In the text field, you need to type in the JavaScript that will close the window. The script is quite simple. In the text field, type window.close (). After you type that script, choose OK.

  6. Dreamweaver automatically places the JavaScript in the head portion for the HTML document and hyperlinks the selected button to call that script. Save the document by choosing File, Save.

  7. Open trigger.html and preview it in the browser. When the page first loads, the pop-up window appears, this time with a Close button. Click the Close button and the pop-up window will close.

The call JavaScript behavior can be used for a variety of scripts, but this should give you a working example of why you might want to use this behavior in real-world development.


    Team-Fly    
    Top


    Macromedia Dreamweaver MX Unleashed
    Macromedia Dreamweaver MX 2004 Unleashed
    ISBN: 0672326310
    EAN: 2147483647
    Year: 2002
    Pages: 321

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