to explain the problem here is a short description of the context:
I am building project micro sites for the programming work that students did in their semester. To showcase the work (it is done in processing p5js) I want to use Iframes where the script will run in.
To do this I did it like described here: https://github.com/processing/p5.js-website/blob/master/js/examples.js#L133
Because the files are coming from an backend I do it like this: I create an iframe and after wards I want to add the script files to it. How ever it does not render anything.
<div class="col-sm-7 middle-col col-sm-offset-3">
<iframe id="uid" width="100%" height="500" src="assets/p5/p5-iframe-template.html"></iframe>
<script>
var iframe = document.getElementById("uid");
iframe.onload = function() {
var userScript = iframe.contentWindow.document.createElement('script');
userScript.type = 'text/javascript';
userScript.src = '<?php echo(($content->pfile()->toFile()->url())) ?>';
userScript.async = false;
iframe.contentWindow.document.body.appendChild(userScript);
};
</script>
</div>
The problem now is that if I get the url of the file and append it, it seems that the iframe does not reload itself and nothing gets displayed (just a blank white canvas).
If I try a different approach and change the script tag's text property like this:
userScript.text = '<?php echo(($content->pfile()->toFile()->content())) ?>';
I will get a Javascript error that looks like the following:
Either way I'm doing it I can not find a solution. I tried refreshing the Iframe by changing it's src attribute but this does not seem to work? Maybe you can help me out.
Related posts I already read and tried: Creating an iframe with given HTML dynamically
Greetings