Using JavaScript with Dreamweaver 4

One of the most exciting capabilities of Dreamweaver is it's built in support for JavaScript. Let's examine this feature and how it works.

In order to use JavaScript, you need to realize there are some important considerations. First, you need to consider the particular html tag the JavaScript will be linked to. In DW, you'll see a list of the available tags at the location of the cursor at the lower left hand corner of the page.

This will change based on where the cursor is located. It's also important because not all tags can be used to trigger JavaScripts in the particular browser you are using. This is the second consideration. As we have come to know (and love) Netscape & Internet Explorer do NOT necessarily support JavaScript the same way. Ironically, Internet Explorer has a much broader range of ways to trigger JavaScripts. In order to determine this, you'll need to open the Behaviors menu in DW.

This is the gateway to most JavaScript control in the program. Notice at the top of the palette the particular html tag you are using is listed.

Also, notice the Events and Actions columns?

 

To place a JavaScript, begin by selecting the <body> tag and then click on the plus sign on the behaviors palette. You'll see a list of the available actions. If this is greyed out, that means you selected a tag which cannnot trigger JavaScript. Select Check Browser.

This will test to see which browser the user is running. Based on what it finds, it can leave the user on the page, or route them to another one designed for their browser.

Once it's set up, click ok

Now, you can select the particular trigger (or "Event") by clicking on the small pointer icon

This list will vary based on the tag and the browser you are designing for. To change to a different browser, select the browser at the top of the Behaviors menu (DW 3) or select it at the bottom of this menu (DW4). Normally, I recommend using 4.0 or Later Browsers as this covers the broadest range of browsers (including 90% of the 3.0 browsers). Change to IE 5.0 and notice the different triggers.

To see your script run, test your page in a browser. Viola!

Amazon Honor System Click Here to PayLearn More