88
Views
4
Comments
Solved
Include external js file with data attributes

HI all,

I would like to integrate a calendar widget from another Cloud application in which appointments can be made. I have a reactive web app and to do this, I need to include an external js file with data attributes somewhere between the <body> tags. According to the documentation of the widget I need to include a <script> tag with attributes like data-apikey and data-configuration. How do I include a js file with data attributes?

Because of the data attributes I think importing the js file is not an option. Because my app is a RWA there is no expression with the escaping content option. I've tried some other options I found on the forum but each time I'm running into the problem of passing the data attributes.

Can't imagine this can't be done. I'm probably doing something wrong here. Can anyone please help me out? Thanks in advance.

2020-09-18 09-37-36
Devendra Baghel
Solution

Hi Ramon,

You can use some think like below

script.setAttribute("data-apikey", "XXXXXXXXXXXX");

Best Regards

Devendra Baghel

2019-11-14 12-29-35
Ramon Pigmans

Devendra Baghel wrote:

Hi Ramon,

You can use some think like below

script.setAttribute("data-apikey", "XXXXXXXXXXXX");

Best Regards

Devendra Baghel

 Works like a charm! Thanks Devendra!

 

2020-09-18 09-37-36
Devendra Baghel

Hi Ramon,

You can add JavaScript file in react web app by Adding a javascript block and adding a javascript file in body by using javascript code same as in attached image


Best Regards

Devendra



2019-11-14 12-29-35
Ramon Pigmans

Devendra Baghel wrote:

Hi Ramon,

You can add JavaScript file in react web app by Adding a javascript block and adding a javascript file in body by using javascript code same as in attached image


Best Regards

Devendra



 Thanks for your answer Devendra. I've tried that, but how do I pass the data attributes? The aren't part of the src and if I add script.data-apikey I get an error. Any ideas?

 

2020-09-18 09-37-36
Devendra Baghel
Solution

Hi Ramon,

You can use some think like below

script.setAttribute("data-apikey", "XXXXXXXXXXXX");

Best Regards

Devendra Baghel

2019-11-14 12-29-35
Ramon Pigmans

Devendra Baghel wrote:

Hi Ramon,

You can use some think like below

script.setAttribute("data-apikey", "XXXXXXXXXXXX");

Best Regards

Devendra Baghel

 Works like a charm! Thanks Devendra!

 

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