... Elxis version 2009.2 codename Electra is out, download it from Elxis Download Center (EDC) ...
OnLoad in body tag
From Elxis Official Documentation
Elxis 2009.0, or newer, has a build-in function that allows developers to load JavaScript in body tag using the attribute onload. To be able to perform this task the template should be compatible with this feature.
Contents |
How to enable onload feature on your template
If you are going to use the template on Elxis 2009.0 or newer you can safely add the following to your template's index.php file.
<?php /* safe to be added on Elxis 2009.0+ web sites templates */ ?> <body<?php echo $mainframe->onLoad(); ?>>
If you are developing a general purpose template for public distribution (free or commercial) then it is not sure that the web sites that will use that template will have 2009.0+ or a previous Elxis version installed. In this case you should check if this feature exist. Use the following code in your template's index.php file to perform this check.
<?php /* safe to be added on ANY Elxis template */ ?> <body<?php echo (method_exists($mainframe, 'onLoad')) ? $mainframe->onLoad() : ''; ?>>
Why to use onLoad?
Well, there are some cases where PHP developers need to add stuff to the body tag to be executed when the page loads. As this tag is on the template's index.php file this can not be done. The onLoad feature makes PHP developers much happier and solves this problem. As an example a PHP developer can now easily append a javascript function to the body tag that will turn form's autocomplete to off (He can not do it via HTML as the generated HTML code will be XHTML invalid).
How to add stuff on body's onload attribute
If you are a developer you can easy append JavaScript functions to the body's onload attribute. To do so you should use the addonLoad method of the $mainframe object.
But before you do so you must check if the installed Elxis version support this feature. If you don't do so then if the web site runs Elxis 2008 or 2006 PHP will generate a warning! To check if this feature is supported by the installed Elxis follow one of the following methods.
<?php /* 1st method, check Elxis version */ global $_VERSION; if ($VERSION->RELEASE > 2008) { //feature is supported } /* 2nd method, check if method exists */ if (method_exists($mainframe, 'addonLoad')) { //feature is supported } ?>
Usage example 1
Add a javascript function (changebgcolor) to be executed when the body loads.
$myjs = 'changebgcolor()'; $mainframe->addonLoad($myjs);
Usage example 2
You can add more functions if you wish to be executed when the body loads.
$mainframe->addonLoad('changebgcolor()'); $mainframe->addonLoad('setautocompleteoff()'); $mainframe->addonLoad('mycustomfunction(input)');
| The call of the addonLoad method should be done before html gets echoed. So you can use this feature on components and bots but not on modules. If the template is not compatible then your additions to the body tag won't be echoed. |

