I'm trying to insert the html content in a few iFrames and I got a strange javascript error when I'm adding a tag. The code I want to insert looks like (on the real example there is some code) :

  <script>/*This line is causing the problem */</script>
  <h1 style='text-align: center;'>This IS an iframe</h1>

the js errror is : Uncaught TypeError: Cannot read property 'appendChild' of null (you need to be in development mode). If you remove the line the error will not longer exist.

The simplified source code example: https://codepen.io/anon/pen/MdoLpq

I'm a bit lost here, any ideas or hints are welcomed.

1 Answers

Levi Cole On Best Solutions

I'm pretty sure jQuery strips out <script> tags when using the .html() method. To get around this use plain javascript .innerHTML.

For example, instead of..

$("#1").contents().find('html').html( frameCode );

Replace with this...

$("#1").contents().find('html').get(0).innerHTML = frameCode;