Results 1 to 4 of 4

Thread: how to add javascript by code?

  1. #1
    User
    Join Date
    11-23-09.
    Location
    Valais, Switzerland
    Posts
    77

    Default 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

  2. #2
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: how to add javascript by code?

    Try
    Code:
    $GLOBALS['TL_HEAD'][] = '<script type="text/javascript">$myValue... function()...</script>';

  3. #3
    User
    Join Date
    11-23-09.
    Location
    Valais, Switzerland
    Posts
    77

    Default 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?

  4. #4
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: how to add javascript by code?

    Of course. I use it and works pretty well.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •