Objective

To load a JavaScript file into a Joomla PHP page.

Example

Defining URL of the JavaScript file in $url variable...

$url = "components/com_mycomponent/assets/js/script.js";

Loading $url JavaScript file...

$document = JFactory::getDocument();
$document->addScript($url);

N.B.: It used to be possible with JHTML. However, this was deprecated in Joomla 2.5 and removed in Joomla 3.x.


See also

Source

 

Keep Me Informed

Keep me informed of the latest extensions releases and offers. One email maximum per month.

Offer Me A Coffee!

If you like my work, offer me a coffee! Nick.