JDocument/addScript
From Joomla! Documentation
< JDocument(Difference between revisions)
(Fixed bizarre quotes & added real example) |
m (Example depends on document type.) |
||
| Line 26: | Line 26: | ||
$doc->addScript("http://www.example.com/js/myscript.js"); | $doc->addScript("http://www.example.com/js/myscript.js"); | ||
</source> | </source> | ||
| − | + | 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: | |
| − | + | <source lang="html4strict"> | |
| − | <source lang=" | + | |
<script type="text/javascript" src="http://www.example.com/js/myscript.js"></script> | <script type="text/javascript" src="http://www.example.com/js/myscript.js"></script> | ||
</source> | </source> | ||
Latest revision as of 12:15, 10 November 2008
Adds the definition of a linked external script to the document object. Duplicates are ignored.
[edit] Syntax
void addScript( $url, $type )
where:
| Argument | Data type | Description | Default |
|---|---|---|---|
| $url | string | URL of script. | |
| $type | string | MIME type of script. | 'text/javascript' |
[edit] 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>