Bradford Web Designer

website design tips and traps

My latest coding trick is the Javascript onLoad replacement. I won’t take any credit for it, as it’s well-documented throughout the web, in various forms. All I want to say on the matter is that it’s especially useful for Dreamweaver users, like me.

Traditionally, scripts can be launched after a page is loaded by adding functions to a BODY element ‘onload’ attribute. Unfortunately, it makes code look messy, and it’s fiddly to manage in template form, when different pages run different scripts. In the past, I’ve had to create an Editable Attribute and use Dreamweaver’s Template Properties menu to update the onload value — not ideal!

By using the Javascript ‘onload’ event, you can list scripts in the HEAD section (say, in a ‘head’ Editable Section), where they are better placed for readability and manageability. A default OnLoad section can be placed in your template, either before site building starts, or as a Library Item, which can be updated at a later time. Either way, the Javascript should look something like this:


window.onload = function() {
myfunction1();
myfunction2();
}

…replacing ‘myfunction1()’ etc. with the functions or scripting of your choice.

Similar Posts

Add A Comment

©2008 Keith Nuttall, Yammer Web Design. Powered by WordPress.