Hi,
I am editing a plugin, which listens to the onWebPagePrerender event, and I would like it to use the regClientStartupScript function to add a javascript link to the header. However, it does not appear to work. I suspect the plugin would need to listen to some other event also. However I don’t know which one - and I can only find documentation for the onWebPagePrerender event.
Is there a way to add a javascript link to the header in a plugin?
Thanks,
Michal.
I am not positive, but trying to insert something into the<head></head> tags before they have been redered (onWebPagePrerender) is bound to fail.
Perhaps OnParseDocument or OnWebPageInit would be better choices. I have not had a chance to test these in that situation so this is just a recommendation... Not guarenteed to work.
-sD-
Dr. Scotty Delicious, Scientist.
-
MODX Staff
- 1,535 Posts
I think the problem here is that onWebPagePrerender is the very last event to be called before the web content is outputted to the screen, and occurs after any regClientStartup scripts have been merged.
Using the onParseDocument event, as Scotty mentioned, should be fine as it happens immediately before the regClientStartup scripts are merged into the output.
Garry Nutting
Senior Developer
MODX, LLC
Email:
[email protected]
Twitter: @garryn
Web: modx.com
-
MODX Staff
- 10,725 Posts
The problem with onParseDocument is that it gets called numerous times, and your plugin would get executed multiple times. Though it shouldn’t duplicate the script being registered, it does add unnecessary code execution.
Try the onLoadWebDocument event, though make sure you clear your cache so pages are regenerated with the registered script when being cached.
Thanks - the OnLoadWebDocument event works great. (Although it took me a while to realise it has to have a capital "O"!)
Michal.