I think what I've got might not require much adjusting, but when I try the following:
<div id="exp_div"></div>
<script>
procedure = [
[
"content 1","content 2"
]
]
procedure.forEach(function(this_proc,index){
$("#exp_div").append("<iframe id='trial"+index+"' width='800px' height='800px'></iframe>");
trial_iframe_code = '';
for(var i = 0; i < this_proc.length; i++){
trial_iframe_code += "<iframe id='post"+i+"'></iframe>";
}
doc = document.getElementById('trial'+index).contentWindow.document;
doc.open();
doc.write(trial_iframe_code);
doc.close();
for(var i = 0; i < this_proc.length; i++){
trial_content = this_proc[i];
console.dir(trial_content);
doc = document.getElementById('trial'+index).contentWindow.document.getElementById('post'+i);
doc.open();
doc.write(trial_content);
doc.close();
}
})
</script>
i.e. at this fiddle (iframes don't work as well when i try to run the code on SO) I get the error that "doc.open is not a function" - which I think relates to the attempt to write on the "post" iframe within the trial iframe. Is it possible to write to an iframe within an iframe in this sort of structure? Is my code close to correct, or is a different approach required?
To clarify, this is for an online psychology experiment to create all the tasks the participant will do in a series of iframes. As some of the tasks will have multiple tasks within them, I want to write multiple iframes within an iframe when this happens.
Working code in this case would produce an iframe called "trial0" within "exp_div". Within "trial0" there would be an iframe with id "post0" which just has "content 1" written in it, and an iframe with id "post1" which has "content 2" written in it.