0

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) :

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

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.

3
  • @RandyCasburn, mate don't be to lazy ... Commented May 18, 2019 at 14:31
  • Me? Post your code with your question - don't be lazy! Commented May 18, 2019 at 14:32
  • You don't see the codepen link? : codepen.io/anon/pen/MdoLpq Commented May 18, 2019 at 14:35

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.