Actions

JDocumentHTML/addCustomTag

From Joomla! Documentation

Revision as of 05:02, 13 February 2009 by Clogan (Talk | contribs)

Adds a custom HTML string to the document head.

Syntax

void addCustomTag( $html )

where:

Argument Data type Description Default
$html string Custom HTML string to be added.

Example

Adding a comment to the HTML head section:

$doc =& JFactory::getDocument();
$doc=>addCustomTag( '<!-- This is a comment. -->' );

Adding dynamic javascript to the HTML head section:

function getJavaScript($message){
    $javascript = "<script type=\"text/javascript\">\n\n";
    $javascript .= "if(window.addEventListener){ // Mozilla, Netscape, Firefox";
    $javascript .= "    object.addEventListener(\"load\", function{ alert(\"$message\");}, false);";
    $javascript .= "} else { // IE";
    $javascript .= "    object.attachEvent(\"onload\", function{ alert(\"$message\");});";
    $javascript .= "}";
    $javascript .= "</script>\n\n";
    return $javascript;
}
 
$doc =& JFactory::getDocument();
$doc=>addCustomTag( getJavaScript("This will appear in an alert box after the page loads.") );

In the above example it would have been just as easy to say, pull the string from a database and pass it to getJavaScript instead of using the const string that is in the example.

See also