How to remove body tag onload events
For our purposes, you need only do this if:
- you want diva products to support MacIE5 and
- your page's head tag has onload events hard-coded in it, like this:
<body onload="foo(arg1,arg2);bar(arg3);">
Otherwise, diva users need not follow these instructions. In fact there one real downside of this technique in Dreamweaver: the User Interface of Behaviors will absolutely not understand what you have done. Should you need later to change one of the DW Behaviors on your page, you could always undo what you've done here, temporarily, make the changes in the Behavior's UserInterface, and then move things back to window.onload. Bummer. Hopefully some day soon Dreamweaver will eliminate its use of body onload events.
(As an aside I should point out that there are other more complex ways to fire onload events. In fact diva products use one such method, a variant of http://www.dustindiaz.com/rock-solid-addevent/, which seems to work very well and does not interfere with Dreamweaver in any way.)
Here are the simple steps:
- In the Head of your document, first check for the presence of "window.onload" Then either add to the existing one using its particular technique (because there are several ways of skinning this cat), or create your own like this:
-
<script type="text/javascript"> -
<!-- -
window.onload=function(){ -
foo(arg1,arg2); -
bar(arg3); -
} -
//--> -
</script>
-
- Then clean up the body tag, so this:
<body onload="foo(arg1,arg2);bar(arg3);">
<body>
That's all there is to it! Of course now you have to test your handiwork. But if all goes according to plan, each of those transplanted functions will fire properly, as will any diva functions (which are obviously using a different technique entirely, since you do not see them in either window.onload or in the body tag.)
- E Michael Brandt
Unobtrusive Scripts and Dreamweaver Extensions