Index: openacs-4/packages/acs-templating/tcl/head-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/head-procs.tcl,v diff -u -r1.20.2.3 -r1.20.2.4 --- openacs-4/packages/acs-templating/tcl/head-procs.tcl 5 Sep 2016 11:34:40 -0000 1.20.2.3 +++ openacs-4/packages/acs-templating/tcl/head-procs.tcl 9 Sep 2016 08:12:25 -0000 1.20.2.4 @@ -695,10 +695,26 @@ unset body_handlers($name) } - # Now create the event handlers string + set js "" foreach {event script} [array get body_handlers] { - append event_handlers " " $event = \" [join $script { }] \" + # + # Remove the "on" prefix if provided. E.g. "onload" is + # mapped to the "load" event on "window" (UIevent). It + # would as well be possible to map to DOM events (on + # "document") + # (https://developer.mozilla.org/en-US/docs/Web/Events) + # + regsub ^on $event "" event + append js [subst { + window.addEventListener('$event', function () { + [join $script { }] + }); + }] } + if {$js ne ""} { + template::add_body_script -script $js + } + unset body_handlers }