how to add javascript by code?
Hello,
I know how to add a javascript file by : "$GLOBALS['TL_JAVASCRIPT'][] = ", but know I need to do it by code.
I need to add a dynamic javascript to my page that must be generated by code (not in a file). How to do it?
So in my HTML page I do not want that :
Code:
<script type='text/javascript' src='../myFile.js'></script>
But that :
Code:
<script type='text/javascript'>
$myValue... function()...
</script>
Thanks
Re: how to add javascript by code?
Try
Code:
$GLOBALS['TL_HEAD'][] = '<script type="text/javascript">$myValue... function()...</script>';
Re: how to add javascript by code?
hello,
Ok this is woking in config.php, but not when I call it in the code. Can we use
Code:
$GLOBALS['TL_HEAD'][]
where we want in code?
Re: how to add javascript by code?
Of course. I use it and works pretty well.