Foren / Cotonti / Development / Loading custom JS script in plugins

Tip

ez
#23213 26. Februar 2010, 05:26
I found this usefull.. and will share it with you :)

If you need a custom js script for a plugin, DO NOT load it always in the header.tpl...
OR {HEADER_COMPOPUP} tags, you CAN load jquery plugins or other scripts only when you really need them with the following code:

function addJavascript(jsname,pos) {
	var th = document.getElementsByTagName(pos)[0];
	var s = document.createElement('script');
	s.setAttribute('type','text/javascript');
	s.setAttribute('src',jsname);
	th.appendChild(s);
}

look at: Link to article

So keep your code clean, and only load stuff when needed.. B)
==- I say: Keep it EZ -==