2 posts
on 8/24/2004
JavaScript hack for those sometimes errors
Posted Tuesday, August 24, 2004 1:52:32 PM by Tom Muck

Have you ever built a page with a simple JavaScript that works most of the time but sometimes gives you a JavaScript error "Object expected"? Many times this is caused by a JavaScript executing before the page is fully loaded. It happens frequently with mouseovers -- especially menus that are at the top of a page. What happens is that a user will type the URL into the browser, and as the page is loading the mouse is brought over a mouseover. Because the document is not fully loaded, the object cannot be located.
One trick (read: cheesy hack workaround) I use to overcome this problem is to use a JavaScript try/catch block. A try/catch block is saying "try this, and if it doesn't work do this instead". A try/catch block effectively stops an error in its tracks. For an error handling routine it is a lifesaver, but for an annoying "sometimes" error, it is simply a nice workaround. The most basic syntax is this:
try {
// code you want to "try"
}catch(e) { // "e" is the error
// code to execute in the event of an error
}
Use it like this:
- Find the culprit script that throws the error. It's usually a mouseover of some variety.
- Add the try/catch around it.
Here is a simple example. Suppose a link has a mouseover event like this:
onmouseover="doRollover('myImage')"
Every once-in-a-while you will see a JavaScript error on this bit of script. Add the try/catch:
onmouseover="try{doRollover('myImage') }catch(e){};"
That's it. The catch block does nothing -- it simply exists to fill out the try/catch block, but has no alternative operation. When the page is fully loaded, the script will execute normally.
Category tags: Dreamweaver
Posted by Tom Muck
Add comment |
View comments (1) |
Permalink
|
Trackbacks (0)
|
Digg This
Undocumented Dreamweaver: reloadSnippetList, I wonder what this does?
Posted Tuesday, August 24, 2004 1:49:00 PM by Paul R. Boon

Latest Posts by Paul R. Boon
- Undocumented Dreamweaver: Getting Snippets as a Collection of TreeNodes
- Undocumented Dreamweaver: A Completely Pointless API Call
- Undocumented Dreamweaver: Getting the Path of the Menus.xml file
- Undocumented Dreamweaver: Changing the Cursor During Time Consuming Code
- Undocumented Dreamweaver: Determining the Location of the All User Configuration Folder
For developers developing extensions to manipulate snippets, the main issue has been the lack of an API call to force the Snippets panel to refresh itself. This especially becomes an issue when your extension makes dynamic changes to the Snippets folder within Dreamweaver's configuration directory.
An undocumented API call comes to the rescue once again, this time in the shape of:
dreamweaver.snippetPalette.reloadSnippetList()
dw.snippetPalette.reloadSnippetList()
This handy API call simply reloads the Snippet Panel showing any and all changes made to the snippets folder structure.
Category tags: Dreamweaver, Extensibility
Posted by Paul R. Boon
Add comment |
View comments (0) |
Permalink
|
Trackbacks (0)
|
Digg This
2 posts
on 8/24/2004


Blog RSS feed












