Hi, I have a simple html page which will dynamically creates an iframe (using javascript) when clicks on a hyperlink. My problem is I want to write some text message (e.g: Hello World) inside the iframe with a delay time of 5 seconds after the iframe being created. It will be good if the time control can be done within the iframe and not from the parent, as the message and delay mechanism happen only after iframe created. Below is some code snippet.
HTML Code:
<html>
<head>
<script type="text/javascript">
function createFrame() {
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','frameID');
tempIFrame.style.border='1px solid';
tempIFrame.style.width='250px';
tempIFrame.style.height='100px';
tempIFrame.style.visibility="visible";
var IFrameObj = document.body.appendChild(tempIFrame);
if (IFrameObj.contentDocument) {
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
IFrameDoc = IFrameObj.document;
} else {
alert('Problem creating iframe');
}
return false;
}
</script>
</head>
<body>
<a onclick="createFrame();" href="#">Click Me</a>
</body>
</html>
I am thinking of using the setTimeout() function in the iframe but have no idea how to dynamically create it. Sample code is most welcome and hope to get some answers from this forum. Thank you.