JDocument/addScript
From Joomla! Documentation
< JDocument(Difference between revisions)
m (Missed & in code sample.) |
(Fixed bizarre quotes & added real example) |
||
| Line 24: | Line 24: | ||
<source lang="php"> | <source lang="php"> | ||
$doc =& JFactory::getDocument(); | $doc =& JFactory::getDocument(); | ||
| − | $doc->addScript( | + | $doc->addScript("http://www.example.com/js/myscript.js"); |
</source> | </source> | ||
| + | |||
| + | Example code will produce following link: | ||
| + | <source lang="javascript"> | ||
| + | <script type="text/javascript" src="http://www.example.com/js/myscript.js"></script> | ||
| + | </source> | ||
| + | |||
===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-Framework/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> | ||
Revision as of 12:00, 10 November 2008
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>