Actions

Difference between revisions of "JDocument/addScript"

From Joomla! Documentation

m (Example depends on document type.)
m (See also: Framework => Platform)
 
Line 32: Line 32:
  
 
===See also===
 
===See also===
* [http://api.joomla.org/Joomla-Framework/Document/JDocument.html#addScript JDocument->addScript on api.joomla.org]
+
* [http://api.joomla.org/Joomla-Platform/Document/JDocument.html#addScript JDocument->addScript on api.joomla.org]
 
* [[JDocument/addScriptDeclaration|JDocument->addScriptDeclaration]]
 
* [[JDocument/addScriptDeclaration|JDocument->addScriptDeclaration]]
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocument]]</noinclude>
 
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocument]]</noinclude>

Latest revision as of 03:21, 25 September 2013

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");

How this is rendered depends on the document type. If the document type is HTML then this code will produce following link in the HTML HEAD section:

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

See also