|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
The latest technique makes a consistent API for adding code into the document:
The new template::head and template::add_body_handler
Adds javascript code to an event handler in the body tag. Several javascript code blocks may be assigned to each handler by subsequent calls to template::add_body_handler.
If your script may only be added once you may supply an identifier. Subsequent calls to template::add_body_handler with the same identifier will replace your script rather than appending to it.
event may be one of:
@param event the event during which the supplied script should be executed
@param script the javascript code to execute
@param identifier a name, if supplied, used to ensure this javascript code is only added to the handler once
DEPRECATED:
There was no easy way to add onload event to openacs, unless you edit www/site-master.tcl, but now you can define within you own package what functions you want to be for onload javascript event. This tcl callback definition will work for any page.
ad_proc -public -callback subsite::header_onload -impl my_onload {} {
return the function to load when the page is served
} {
return {my_javascript_function();}
}
Or in case you want it for a single page, or for you custom template, use the template property to send it:
<property name="body(onload)">
my_javascript_function();
</property>
Alternatively, as the on_load property tag has been deprecated, you could in your .tcl file set a variable
set my_function_name "my_javascript_function();"
then in the .adp
<property name="body(onload)">
@my_function_name;noquote@
</property>