| API | Package | Subpackage | Class | Method | Reference | Last reviewed | Doc status |
|---|---|---|---|---|---|---|---|
Home |
Joomla.Framework |
Document |
JDocument |
addScriptDeclaration |
addScriptDeclaration() |
Never | Work in Progress |
Adds a script into the head block of the current page.
void addScriptDeclaration ( $content, $type )
| $content | string | is a string containing the script that is to be added to the page. |
| $type | string | is a string containing the mime-type of the script. This parameter is optional and if omitted defaults to ‘text/javascript’. |
This example adds a short script to the page.
Example
global $mainframe; $script = "alert( 'A script has been added to the page!' );"; $document = &JFactory::getDocument(); $document->addScriptDeclaration( $script );
Might add the following to the head of the document:
Result
<script type="text/javascript"> // <!-- alert( 'A script has been added to the page!' ); // --> </script>