views:

57

answers:

2

I am dynamically creating an iframe with javascript inside the body.

iframe = m_oYDOM.get("ifAdwords");

iframe.contentWindow.document.body.innerHTML = <script type=\"text/javascript\">function Test(){alert(\"Success\");Test();}</script>";

I am not able to get the alert to work. Can someone help me!

A: 

.innerHTML is only for text changes... Call the script from another *.html file. OR just add onload to the end of iframe like so:

<iframe src="test.html" onload="alert('Success')";>
David
A: 

I got this working

iframe = document.getElementByID("iFrameID");
var oDoc = iframe.contentWindow.document;
oDoc.open();
oDoc.write('<html><body><script type=\"text/javascript\">function Test(){alert(\"success\");}Test();<\/script><\/body><\/html>');
oDoc.close();
kishore