I've created a shadow dom in javascript and everything is working as intended. Except, I want to add a remote JS script to it and consume a function it contains. But don't know how to do this.
This is an piece of code I use for the creation of my shadow DOM:
var shadowDom = this.attachShadow({ mode: 'open' });
var html = "<div class='stuff'>Hi!</div>";
let wrapper = document.createElement('div');
wrapper.innerHTML = html;
const js = document.createElement('script');
js.setAttribute('src', 'http://mywebsite.com/js/code.js');
shadowDom.appendChild(js);
shadowDom.appendChild(wrapper);
The code.js script includes:
function test()
{
alert("ok");
}
How can I call the test() function once I've added the code.js to my shadow DOM inside my widget's script?
Thanks