How to insert html securely in your visual app

Sumedh Chakravorty
1 min readMay 21, 2020

In this tutorial we’ll see the recommended way to insert html string in visual applications. We do not recommend inserting html using data-bind= “html : …” syntax or element.innerHtml since these are prone to xss attacks.

Using oj-bind-dom

Here’s a DOM binding example on Oracle JET Cookbook and link to js doc.

Create a Module function that returns the config required by the DOM binding.

define(['ojs/ojhtmlutils'], function(HtmlUtils) {
'use strict';
var PageModule = function PageModule() {};

PageModule.prototype.getConfig = function() {
const viewStr = '<div> Sample <b>text</b> from <i>module function.</i></div>'
return {
view: HtmlUtils.stringToNodeArray(viewStr),
data: {
}
}
}
return PageModule;
});

Use it in your html

<div class="oj-flex">
<oj-bind-dom config="[[$functions.getConfig()]]"></oj-bind-dom>
</div>

Run it…

Assets

Visual App

Version

VBCS: 19.4.3.1

JET: 8.1.3

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sumedh Chakravorty
Sumedh Chakravorty

Written by Sumedh Chakravorty

Product Manager for Oracle Visual Builder.I talk about Oracle JET, VBCS, React, React Native, Spring Boot. Views are my own.

No responses yet

Write a response