I unsuccessfully tried solving this issue with the solutions found here and here
I prefixed my question with React because my app is running on React and I'd like to learn how to implement it this way.
I have a <script/>
that loads its content accordingly by placing it directly on a mundane HTML page i.e:
codepen
<body>
<div>
<script type="text/javascript" src="https://app.jackrabbitclass.com/jr3.0/Openings/OpeningsJS?OrgID=534011&Cat1=8-Week%20Sessions&hidecols=Gender,Ages,EndDate,Session,Openings&sort=day"></script>
</div>
</body>
However, I'm not able to get the same results inside of a react component i.e:
class Frame extends React.Component {
componentDidMount() {
const script = document.createElement("script");
script.type = "text/javascript";
script.src =
"https://app.jackrabbitclass.com/jr3.0/Openings/OpeningsJS?OrgID=534011&Cat1=8-Week%20Sessions&hidecols=Gender,Ages,EndDate,Session,Openings&sort=day";
script.async = true;
document.querySelector(".frame-container").appendChild(script);
//document.querySelector(".frame-container").insertBefore(script);
//document.querySelector(".frame-container").innerHTML = script;
}
render() {
return <div className="frame-container" />;
}
}
function App() {
return (
<div className="App">
<p>Did Frame load?</p>
<Frame />
</div>
);
}
I get the follwing error:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
How could I properly load the given <script />
content inside of a React Component?
Also, here's a code sandbox