Actions

JDocument/addScript

From Joomla! Documentation

Revision as of 12:00, 10 November 2008 by Depresz (Talk | contribs)

Adds the definition of a linked external script to the document object. Duplicates are ignored.

Syntax

void addScript( $url, $type )

where:

Argument Data type Description Default
$url string URL of script.
$type string MIME type of script. 'text/javascript'

Example

To add a link to some JavaScript code at a specific URL, you could use:

$doc =& JFactory::getDocument();
$doc->addScript("http://www.example.com/js/myscript.js");

Example code will produce following link:

<script type="text/javascript" src="http://www.example.com/js/myscript.js"></script>

See also