1

I am trying to add <script></script> tag to an iframe head or body but not able to succeed.

var iframe = $("iframe#demo),
    contents = iframe.contents(),
    body = contents.find('body');

Attempt one:

var script = document.createElement( 'script' );
script.type = 'text/javascript';
$(body).append(script);

Second attempt:

$("`<script></script>`").appendTo(contents.find('head'))

Either of the method above does not work for me.

Let me know if anyone has some pointer.

Thanks

Viral

jsalonen
  • 29,593
  • 15
  • 91
  • 109
Viral
  • 310
  • 3
  • 19
  • Related question: http://stackoverflow.com/questions/1591135/why-does-appending-a-script-to-a-dynamically-created-iframe-seem-to-run-the – jsalonen Jun 20 '12 at 20:02
  • I saw that...but the problem is when I used it standalone like in the post u gave it works fine. but when I use jquery it does not work. However, quick question Do I need to write all the html,body,head tag inside iframe? – Viral Jun 20 '12 at 20:33

0 Answers0