Hi Folks,
I have one java script code which I need to use in my react application, before this I have used simple JS code in react and it's worked but this is something different I used this one in Inject HTML component and java script widget of outsysetms but it does not work.
please guide me how can I use this one in react app, please find JS code below
I have changed src url and data-domain-script value as I can not paste original value here.
Thanks in advance for the help
Arun Rajput
Hi Arun,
You can try the injection approach described mentioned in this post: https://www.outsystems.com/forums/discussion/55258/load-external-js-in-outsystems-reactive-web-app/#Post270147
Kind regards,
Benjith Sam
Hi @Benjith Sam ,
I have read above post and found this approach which I can use in my case.
var head1 = document.getElementsByTagName('head')[0];var new_script1 = document.createElement('script');new_script1.type = 'text/javascript';new_script1.src = "your_js_url.js?params=" ;new_script1.setAttribute ("data-os-finished", "true");new_script1.charset = "utf-8";head1.appendChild(new_script1);
But I have doubt as you can see in java script code which is provided by me in this we have one attribute and it's value "data-domain-script". How can I use this attribute in above given approach.
Thanks,
Arun
You can set the 'data-domain-script' attribute to the script element using the setAttribute() method as shown below
new_script1.setAttribute('data-domain-script', 'xxzz-yy32-key');
Hi Benjit,
As you suggested I have use java script in same format but getting following error at console of browser. Please find below snapshot and let me know what I am missing there.
Regards,
Unfortunately I was not able to identify the cause of the encountered issue. To verify if the observed issue is related to OutSystems, I tried to access the same JS file in a plain html document but still encountered the same console exception.
Sorry! I don't have anything specific to share as a solution.
Hi Benjith,
Thanks for your responses till now, with your help now I knew that how we can use this type of java script in react app.
This JS is one trust cookies JS which I have to implement in my project.
When I am using Same JS in traditional app in expression it's working fine.
Thanks for your help.
Arun Rajput.
HI @Benjith Sam ,
Now JS working using the same approach, I was passing wrong values.
Thanks for the solution and help.
You're welcome, Arun. Thank you for the update.
Glad you got it working :)