Class sap.ui.core.HTMLModule: sap/ui/core/HTML

extends Control

Embeds standard HTML in an 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.

Constructor Summary
new sap.ui.core.HTML(sId?, mSettings?)Constructor for a new HTML.
Event Summary
afterRendering(oControlEvent)Fired after the HTML control has been rendered.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.ui.core.HTML.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.core.HTML with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.core.HTML.getMetadata()Returns a metadata object for class sap.ui.core.HTML.
attachAfterRendering(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the afterRendering event of this sap.ui.core.HTML.
detachAfterRendering(fnFunction, oListener)Detaches event handler fnFunction from the afterRendering event of this sap.ui.core.HTML.
fireAfterRendering(mParameters?)Fires event afterRendering to attached listeners.
getContent()Gets current value of property content.
getDomRef(sSuffix?)
getPreferDOM()Gets current value of property preferDOM.
getSanitizeContent()Gets current value of property sanitizeContent.
getVisible()Gets current value of property visible.
setContent(sContent)Sets a new value for property content.
setDOMContent(oDom)Sets some new DOM content for this HTML control.
setPreferDOM(bPreferDOM)Sets a new value for property preferDOM.
setSanitizeContent(bSanitizeContent)Sets a new value for property sanitizeContent.
setVisible(bVisible)Sets a new value for property visible.
Constructor Detail
new sap.ui.core.HTML(sId?, mSettings?)

Constructor for a new 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

  • 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.

Parameters:
stringsId?id for the new control, generated automatically if no id is given
objectmSettings?initial settings for the new control
Event Detail
afterRendering(oControlEvent)

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.

Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
booleanoControlEvent.getParameters.isPreservedDOMWhether 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).
Method Detail
sap.ui.core.HTML.extend(sClassName, oClassInfo?, FNMetaImpl?): function

Creates a new subclass of class sap.ui.core.HTML with name 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.

Parameters:
stringsClassNameName of the class being created
objectoClassInfo?Object literal with information about the class
functionFNMetaImpl?Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
functionCreated class / constructor function
sap.ui.core.HTML.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.core.HTML.
Returns:
sap.ui.base.MetadataMetadata object describing this class
attachAfterRendering(oData?, fnFunction, oListener?): sap.ui.core.HTML

Attaches event handler 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.

Parameters:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.ui.core.HTML itself
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining
detachAfterRendering(fnFunction, oListener): sap.ui.core.HTML

Detaches event handler 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.

Parameters:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining
fireAfterRendering(mParameters?): sap.ui.core.HTML
Fires event afterRendering to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
booleanmParameters.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).
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining
getContent(): string

Gets current value of property 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 changing the content dynamically, ensure that the ID of the root node remains the same as the HTML control's ID. Otherwise it cannot be guaranteed that certain lifecycle events take place.

Returns:
stringValue of property content
getDomRef(sSuffix?): Element
Parameters:
stringsSuffix?, Default: ''Suffix of the Element to be retrieved or empty
Returns:
ElementThe element's DOM reference or null
getPreferDOM(): boolean

Gets current value of property 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 a 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.

Returns:
booleanValue of property preferDOM
getSanitizeContent(): boolean

Gets current value of property 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.

Returns:
booleanValue of property sanitizeContent
getVisible(): boolean

Gets current value of property visible.

Specifies whether the control is visible. Invisible controls are not rendered.

Default value is true.

Returns:
booleanValue of property visible
setContent(sContent): sap.ui.core.HTML

Sets a new value for property 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 changing the content dynamically, ensure that the ID of the root node remains the same as the HTML control's ID. Otherwise it cannot be guaranteed that certain lifecycle events take place.

When called with a value of null or undefined, the default value of the property will be restored.

Parameters:
stringsContentNew value for property content
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining
setDOMContent(oDom): sap.ui.core.HTML
Sets some new DOM content for this HTML control. The content will replace the existing content after the next rendering. Properties are not modified, but preferDOM should be set to true.
Parameters:
ElementoDomthe new DOM content
Returns:
sap.ui.core.HTMLthis to facilitate method chaining
setPreferDOM(bPreferDOM): sap.ui.core.HTML

Sets a new value for property 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 a 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.

Parameters:
booleanbPreferDOMNew value for property preferDOM
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining
setSanitizeContent(bSanitizeContent): sap.ui.core.HTML

Sets a new value for property 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.

Parameters:
booleanbSanitizeContentNew value for property sanitizeContent
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining
setVisible(bVisible): sap.ui.core.HTML

Sets a new value for property 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.

Parameters:
booleanbVisibleNew value for property visible
Returns:
sap.ui.core.HTMLReference to this in order to allow method chaining