JavaScript in the Way? Make It Less Noticable

5/14/2010 12:00 AM By

Here’s a quick tidbit to add to your arsenal of Dreamweaver tips. Let’s say you’re working a freelance design job and you’ve got a site that’s a little creaky. It’s using some old-school inline JavaScript, like this:

<a href="index.html" onClick="window.confirm('Lemme get in your face here for a second.')">

or something similar. While that works great, man, is it ever ugly, and certainly unwieldy.

Dreamweaver has a great function now, as part of the Spry AJAX framework, to “Externalize JavaScript.” You can find that exact command in the “Commands” menu, and running it will process your document, move all of your inline scripts to external documents (and link to them in the <head>), and rewrite your HTML to strip away those nasty inline event handlers, supplying each particular event with unique IDs.

All of this will really clean up your HTML, further creating a separation between markup and scripting, which is definitely healthy for your pages.

Tags: ,

Comments are closed.