Home » Forum
NoNumber!

Joomla!® Websites & Extensions
development  -  support  -  consultancy

I try to respond within 48 hours (excluding weekends).
If I haven't responded by then, feel free to post a reminder or bug me via email.

My last reply was: 4 Hours, 22 Minutes ago.

Welcome, Guest
Please Login or Register.    Lost Password?

How to add JavaScript to the head of the html page
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: How to add JavaScript to the head of the html page
*
#5174
How to add JavaScript to the head of the html page 2 Years, 3 Months ago  
For a piece of javascript code, use:
{source}<?php
    $script = 'your script...';
    $doc =& JFactory::getDocument();
    $doc->addScriptDeclaration( $script );
?>{/source}

To add a js file to the head, use:
{source}<?php
    $doc =& JFactory::getDocument();
    $doc->addScript( JURI::root( true ).'/path/to/your/file.js' );
?>{/source}



To add multiple stylesheets/scripts, you can place 1 php block like:
{source}<?php
    $doc =& JFactory::getDocument();

    $css = 'your css...';
    $doc->addStyleDeclaration( $css );

    $doc->addStyleSheet( JURI::root( true ).'/path/to/your/file.css' );
    $doc->addStyleSheet( JURI::root( true ).'/path/to/your/file2.css' );

    $script = 'your script...';
    $doc->addScriptDeclaration( $script );

    $doc->addScript( JURI::root( true ).'/path/to/your/file.js' );
    $doc->addScript( JURI::root( true ).'/path/to/your/file2.js' );
?>{/source}
Peter van Westen
Admin
Posts: 9169
User OfflineClick here to see the profile of this user
Last Edit: 2010/05/06 12:17 By peter.
The topic has been locked.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
Go to topPage: 1
Moderators: Peter van Westen
Open Source Training | Online Joomla! Training and Support
MaxCDN | Content Delivery Network | Accelerate your site to the max
hosting joomla