Client Unit

From HTML5 Builder
Jump to: navigation, search

A client unit is a client-side script, written in plain JavaScript code.

You can create a new client unit from Home > New > HTML5 Builder Projects > Files > Client Unit, which will be opened on the Code view.

Usage

At Design Time

For a server page or a server mobile page, use the OnShowHeader event to print the HTML code for including the unit:

echo "<script type=\"text/javascript\" src=\"path/to/the/unit.js\"></script>\n";

For an HTML page, use the line directly:

<html>
    <head>
        <script type="text/javascript" src="path/to/the/unit.js"></script></head></html>

Note: You can actually include the script from a place other than the header, if you want to.

For a client page or a client mobile page, you must either use a template and follow the steps for HTML pages, or include the file at runtime.

At Runtime

You can use jQuery’s getScript() method for including a client unit into another client unit or page at runtime:

$.getScript("path/to/the/unit.js", function() {
    // This gets called once the JavaScript file has been successfully loaded.
});

If you don’t want to use jQuery, you can always write your own function to achieve the same result.

See Also