Class sap.ui.core.HTMLModule: sap/ui/core/HTML
Embeds standard HTML in a SAPUI5 control tree.
Security Hint: By default, the HTML content (property 'content') is not sanitized and therefore open to XSS attacks. Applications that want to show user defined input in an HTML control, should either sanitize the content on their own or activate automatic sanitizing through the sanitizeContent property.
Although this control inherits the tooltip
aggregation/property and the hasStyleClass
, addStyleClass
, removeStyleClass
and toggleStyleClass
methods from its base class, it doesn't support them. Instead, the defined HTML content can contain a tooltip (title attribute) or custom CSS classes.
For further hints about usage restrictions for this control, see also the documentation of the content
property.
sClassName
and enriches it with the information contained in oClassInfo
.fnFunction
to the afterRendering
event of this sap.ui.core.HTML
.fnFunction
from the afterRendering
event of this sap.ui.core.HTML
. Accepts an object literal mSettings
that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject for a general description of the syntax of the settings object.
The supported settings are:
- Properties
- content : string
- preferDOM : boolean (default: true)
- sanitizeContent : boolean (default: false)
- visible : boolean (default: true)
- Events
- afterRendering : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]
In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.
{string} | sId? | id for the new control, generated automatically if no id is given |
{object} | mSettings? | initial settings for the new control |
When the control doesn't have string content and no preserved DOM existed for this control, then this event will fire, but there won't be a DOM node for this control.
{sap.ui.base.Event} | oControlEvent | |
{sap.ui.base.EventProvider} | oControlEvent.getSource | |
{object} | oControlEvent.getParameters | |
{boolean} | oControlEvent.getParameters.isPreservedDOM | Whether the current DOM of the control has been preserved (true) or not (e.g. rendered from content property or it is an empty HTML control). |
sClassName
and enriches it with the information contained in oClassInfo
. oClassInfo
might contain the same kind of information as described in sap.ui.core.Control.extend.
{string} | sClassName | Name of the class being created |
{object} | oClassInfo? | Object literal with information about the class |
{function} | FNMetaImpl? | Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata |
{function} | Created class / constructor function |
{sap.ui.base.Metadata} | Metadata object describing this class |
fnFunction
to the afterRendering
event of this sap.ui.core.HTML
. When called, the context of the event handler (its this
) will be bound to oListener
if specified, otherwise it will be bound to this sap.ui.core.HTML
itself.
Fired after the HTML control has been rendered. Allows to manipulate the resulting DOM.
When the control doesn't have string content and no preserved DOM existed for this control, then this event will fire, but there won't be a DOM node for this control.
{object} | oData? | An application-specific payload object that will be passed to the event handler along with the event object when firing the event |
{function} | fnFunction | The function to be called when the event occurs |
{object} | oListener? | Context object to call the event handler with. Defaults to this sap.ui.core.HTML itself |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |
fnFunction
from the afterRendering
event of this sap.ui.core.HTML
. The passed function and listener object must match the ones used for event registration.
{function} | fnFunction | The function to be called, when the event occurs |
{object} | oListener | Context object on which the given function had to be called |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |
afterRendering
to attached listeners. Expects the following event parameters:
isPreservedDOM
of typeboolean
Whether the current DOM of the control has been preserved (true) or not (e.g. rendered from content property or it is an empty HTML control).
{Map} | mArguments? | The arguments to pass along with the event |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |
content
. HTML content to be displayed, defined as a string.
The content is converted to DOM nodes with a call to new jQuery(content)
, so any restrictions for the jQuery constructor apply to the content of the HTML control as well.
Some of these restrictions (there might be others!) are:
- the content must be enclosed in tags, pure text is not supported.
- if the content contains script tags, they will be executed but they will not appear in the resulting DOM tree. When the contained code tries to find the corresponding script tag, it will fail.
Please consider to consult the jQuery documentation as well.
The HTML control currently doesn't prevent the usage of multiple root nodes in its DOM content (e.g. setContent("<div/><div/>")
), but this is not a guaranteed feature. The accepted content might be restricted to single root nodes in future versions. To notify applications about this fact, a warning is written in the log when multiple root nodes are used.
{string} | Value of property content |
{string} | sSuffix?, Default: '' | Suffix of the Element to be retrieved or empty |
{Element} | The element's DOM reference or null |
preferDOM
. Whether existing DOM content is preferred over the given content string.
There are two scenarios where this flag is relevant (when set to true):
- for the initial rendering: when an HTML control is added to an UIArea for the first time and if the root node of that UIArea contained DOM content with the same id as the HTML control, then that content will be used for rendering instead of any specified string content
- any follow-up rendering: when an HTML control is rendered for the second or any later time and the preferDOM flag is set, then the DOM from the first rendering is preserved and not replaced by the string content
As preserving the existing DOM is the most common use case of the HTML control, the default value is true.
Default value is true
.
{boolean} | Value of property preferDOM |
sanitizeContent
. Whether to run the HTML sanitizer once the content (HTML markup) is applied or not.
To configure allowed URLs please use the whitelist API via jQuery.sap.addUrlWhitelist.
Default value is false
.
{boolean} | Value of property sanitizeContent |
visible
. Specifies whether the control is visible. Invisible controls are not rendered.
Default value is true
.
{boolean} | Value of property visible |
content
. HTML content to be displayed, defined as a string.
The content is converted to DOM nodes with a call to new jQuery(content)
, so any restrictions for the jQuery constructor apply to the content of the HTML control as well.
Some of these restrictions (there might be others!) are:
- the content must be enclosed in tags, pure text is not supported.
- if the content contains script tags, they will be executed but they will not appear in the resulting DOM tree. When the contained code tries to find the corresponding script tag, it will fail.
Please consider to consult the jQuery documentation as well.
The HTML control currently doesn't prevent the usage of multiple root nodes in its DOM content (e.g. setContent("<div/><div/>")
), but this is not a guaranteed feature. The accepted content might be restricted to single root nodes in future versions. To notify applications about this fact, a warning is written in the log when multiple root nodes are used.
When called with a value of null
or undefined
, the default value of the property will be restored.
{string} | sContent | New value for property content |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |
{Element} | oDom | the new DOM content |
{sap.ui.core.HTML} | this to facilitate method chaining |
preferDOM
. Whether existing DOM content is preferred over the given content string.
There are two scenarios where this flag is relevant (when set to true):
- for the initial rendering: when an HTML control is added to an UIArea for the first time and if the root node of that UIArea contained DOM content with the same id as the HTML control, then that content will be used for rendering instead of any specified string content
- any follow-up rendering: when an HTML control is rendered for the second or any later time and the preferDOM flag is set, then the DOM from the first rendering is preserved and not replaced by the string content
As preserving the existing DOM is the most common use case of the HTML control, the default value is true.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is true
.
{boolean} | bPreferDOM | New value for property preferDOM |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |
sanitizeContent
. Whether to run the HTML sanitizer once the content (HTML markup) is applied or not.
To configure allowed URLs please use the whitelist API via jQuery.sap.addUrlWhitelist.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is false
.
{boolean} | bSanitizeContent | New value for property sanitizeContent |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |
visible
. Specifies whether the control is visible. Invisible controls are not rendered.
When called with a value of null
or undefined
, the default value of the property will be restored.
Default value is true
.
{boolean} | bVisible | New value for property visible |
{sap.ui.core.HTML} | Reference to this in order to allow method chaining |