you could sole it using params in your template/controller and response.
same idea as returning json. which you can find good tutorials in this forum.
something like this untested pseudocode
if ($filename = param('skriptid')) { // assuming id is filename from iframe src... note: problems with extension might arise
$jsskriptcontent = file_get_contents($content->file(filename)->url());
$tmpl = $roots->assets() . DS . 'p5' . DS . 'p5-iframe-template.html';
$jsskriptcontent = str::template($tmpl, ['INJECT']=> $jsskriptcontent); // template needs {INJECT} somewhere
die(response:success($jsskriptcontent));
} // continue as ususal
and update the iframe to load this
<iframe width="100%" height="500" src="<?php echo $content->url().DS.'skriptid:'.$content->pfile()->filename() ?>">