Body Onload javascript event
API calls for adding javascript
add event listener for a single ID or for a CSS class. When using this call, the provided JavaScript snipped will be added suitable for content security policies (by adding nonces).
Example:
template::add_event_listener \ -id edit-tags-control \ -script [subst {document.getElementById("edit_tags").style.display="block";}]
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.
Add a script to the start of the body section of the document to be returned to the users client.
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>