How can we write in iframe

<html> 
<h2>Write to IFrame using JavaScript</h2>
<script> 
function writeToIFrame() { 
var iframe = document.createElement("iframe"); 
var div = document.getElementById("div"); 
div.appendChild(iframe); 
var doc = null; 
if(iframe.contentDocument) 
doc = iframe.contentDocument; 
else if(iframe.contentWindow) 
doc = iframe.contentWindow.document; 
doc.open(); 
doc.write("Hello World!"); 
doc.close(); 

</script> 
<body onLoad="writeToIFrame();">
<div id="div" style="border: solid 1px; height: 250px; width: 400px;"></div> 
</body> 
</html>

No comments:

Post a Comment

Something Say