The Body
component provides a number of services to the components it wraps. It handles preloading of
images. It provides the ability to add arbitrary JavaScript to the page, to include an external static
JavaScript document, or to add JavaScript
to the
<body>
element's onload event handler. Finally, it provides an easy way
to generate unique identifiers needed for things like image and function names.
When the Body
component renders, it registers itself as an attribute of the IRequestCycle
. This
allows components wrapped by the Body
component, directly or indirectly, to locate it and invoke methods
on it. These methods are used to define preloaded images, and add JavaScript code to the response HTML.
When rendering is complete, the Body
component will have produced four distinct portions of the
HTML response:
<script language="JavaScript" src="..."></script> <script language="JavaScript"><!-- ... function tapestry_onLoad() { } // --> </script> <body onload="javascript:tapestry_onLoad();"> ... </body>
Any number of included static scripts may be added to the page. | |
This script block is only emitted when necessary; that is, because some component needed to generate scripting or initialization (or preloaded images). The block is properly "commented" so that older browsers, those that fail to support scripting, will not be confused by the JavaScript code. | |
The onload event handler function is only generated if some component requests some onload initialization. | |
The | |
The content of the |