Actions

Difference between revisions of "JDocument/addScriptDeclaration"

From Joomla! Documentation

m (Added table formatting.)
m (Missed & in code sample.)
Line 24: Line 24:
 
<source lang="php">
 
<source lang="php">
 
$content = 'alert( \'Hello Joomla!\' )';
 
$content = 'alert( \'Hello Joomla!\' )';
$doc = JFactory::getDocument();
+
$doc =& JFactory::getDocument();
 
$doc->addScriptDeclaration( $content );
 
$doc->addScriptDeclaration( $content );
 
</source>
 
</source>

Revision as of 04:59, 8 September 2008

Adds an internal script to the document object. The script is appended to the document objects' internal script buffer for the specified type.

Syntax

void addScriptDeclaration( $content, $type )

where:

Argument Data type Description Default
$content string Script content.
$type string MIME type of script. 'text/javascript'

Example

To add a Hello World alert in JavaScript, you could use:

$content = 'alert( \'Hello Joomla!\' )';
$doc =& JFactory::getDocument();
$doc->addScriptDeclaration( $content );

Notice that quotation marks in the JavaScript code will need to be escaped by preceding them with a backslash character.

See also