Table of Contents

addScriptDeclaration

API Package Subpackage Class Method Reference Last reviewed Doc status
API Home Package Joomla.Framework Subpackage Document Class JDocument Method addScriptDeclaration Reference addScriptDeclaration() Never Work in Progress

Adds a script into the head block of the current page.

Syntax

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’.

Examples

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>