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,838
  • 7
  • 36
  • 59

1 Answers1

4

Name the frame and do

window.frames["framename"].document.write('<script>...<\/script>');
window.frames["framename"].document.close();
mplungjan
  • 169,008
  • 28
  • 173
  • 236