187
Views
6
Comments
Solved
Add HTML in head tags ODC application
Question
Application Type
Reactive

Hi there,

I need to add a simple script in the <head> tags of my Reactive application (ODC). How do I do this?

I think it's something very simple, but looking around the forum there does not seem to be a clear answer on it.

2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Yes. RequireScript is for loading external javascript files e.g. from a CDN. (https://mycdn.domain.com/mypackage/myscript.min.js)

If you have a downloaded script in your scripts folder there is even a third option to add it to a layout directly.


2025-02-10 17-24-13
Arun Rajput

Hi Eric,

At on ready event of page use below javascript to add script in head.


var script = document.createElement('script');

script.type = 'text/javascript';

script.src = 'url';


document.head.appendChild(script);


Best

Arun

UserImage.jpg
Eric van Heesen

Hi Arun,

Thank you for your response. 

Sorry I'm really not well known with javascript, so where do I put exactly the script? 

The script looks like this:

<!-- Start cookieyes banner --> <script id="cookieyes" type="text/javascript" src="https://...script.js"></script> <!-- End cookieyes banner -->

2021-10-09 07-57-44
Stefan Weber
 
MVP

Hi Eric,

to include an external script to your application, you have two options

* Use the RequireScript client action from the System source (you need to add a reference to it).

RequireScript takes an URL as input and the script handles checking if the script is already required.

Depending on where you need the script you can place it in the OnInitialize event handler of an individual screen or in the Layout block you are using for your application. e.g. LayoutTopMenu.

* Use a Javascript node to inject a script. You would need that if you have additional parameters, e.g. loading the script as module. A sample JavaScript node script would look like this.

const existing = document.getElementById('stencilloader');
if(!existing) {
    const stencilScript = document.createElement('script');
    stencilScript.setAttribute('src','https://unpkg.com/os-aws-location@0.0.1/dist/os-aws-location/os-aws-location.esm.js');
    stencilScript.setAttribute('type','module');
    stencilScript.setAttribute('id','stencilloader');
    document.head.appendChild(stencilScript);
}

This script is taken from my article on how to use StencilJS web components in OutSystems. https://without.systems/using-ionic-stencil-components-in-outsystems-applications#heading-using-a-component-library-in-outsystems-applications

To clarify. Seeing you script you should use the RequireScript client action. You do not have extra parameters so you do not need the custom script approach.

Best

Stefan

UserImage.jpg
Eric van Heesen

Hi Stefan,

Thank you for your reply!

Just to be sure: so with the RequireScript action I only have to add the url - which can be found in the script - as input? So I don't have to put the script itself anywhere else?

2021-10-09 07-57-44
Stefan Weber
 
MVP
Solution

Yes. RequireScript is for loading external javascript files e.g. from a CDN. (https://mycdn.domain.com/mypackage/myscript.min.js)

If you have a downloaded script in your scripts folder there is even a third option to add it to a layout directly.


UserImage.jpg
Eric van Heesen
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.