Back to Document class

Method addScript

public \Joomla\CMS\Document\Document
addScript
(mixed $url, mixed $options = array(), mixed $attribs = array())
Adds a linked script to the page
Parameters
  • string $url URL to the linked script.
  • array $options Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9', 'preload' => array('preload'))
  • array $attribs Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)
Returns
  • \Joomla\CMS\Document\Document instance of $this to allow chaining
Since
  • 1.7.0
Deprecated
  • 5.0
Class: Document
Project: Joomla

Method addScript - Source code

/**
 * Adds a linked script to the page
 *
 * @param   string  $url      URL to the linked script.
 * @param   array   $options  Array of options. Example: array('version' => 'auto', 'conditional' => 'lt IE 9', 'preload' => array('preload'))
 * @param   array   $attribs  Array of attributes. Example: array('id' => 'scriptid', 'async' => 'async', 'data-test' => 1)
 *
 * @return  Document instance of $this to allow chaining
 *
 * @since   1.7.0
 *
 * @deprecated 5.0  Use WebAssetManager
 */
public function addScript($url, $options = array(), $attribs = array())
{
    // Default value for type.
    if (!isset($attribs['type']) && !isset($attribs['mime'])) {
        $attribs['type'] = 'text/javascript';
    }
    $this->_scripts[$url] = isset($this->_scripts[$url]) ? array_replace($this->_scripts[$url], $attribs) : $attribs;
    $this->_scripts[$url]['options'] = isset($this->_scripts[$url]['options']) ? array_replace($this->_scripts[$url]['options'], $options) : $options;
    return $this;
}