JDocumentHTML/addCustomTag
From Joomla! Documentation
< JDocumentHTML(Difference between revisions)
(→Example) |
(→Example) |
||
| Line 38: | Line 38: | ||
$doc=>addCustomTag( getJavaScript("This will appear in an alert box after the page loads.") ); | $doc=>addCustomTag( getJavaScript("This will appear in an alert box after the page loads.") ); | ||
</source> | </source> | ||
| + | |||
| + | 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=== | ===See also=== | ||
* [http://api.joomla.org/Joomla-Framework/Document/JDocumentHTML.html#addCustomTag JDocumentHTML->addCustomTag on api.joomla.org] | * [http://api.joomla.org/Joomla-Framework/Document/JDocumentHTML.html#addCustomTag JDocumentHTML->addCustomTag on api.joomla.org] | ||
<noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocumentHTML]]</noinclude> | <noinclude>[[Category:Development]][[Category:Framework]][[Category:JDocumentHTML]]</noinclude> | ||
Revision as of 05:02, 13 February 2009
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.