2

I have a script such as:

<script> document.body....make something and draw many things in the browser </script>

Which I'd like to execute sandboxed inside an iframe. How can I load this piece of javascript inside the iframe?

I'm trying that which does not work:

document.getElementById('previewFrame').contentWindow.document.body.innerHTML = "<script language='javascript'></script>";

Thanks.

Jordi P.S.
  • 3,618
  • 7
  • 31
  • 58

1 Answers1

4

Name the frame and do

window.frames["framename"].document.write('<script>...<\/script>');
window.frames["framename"].document.close();
mplungjan
  • 155,085
  • 27
  • 166
  • 222