Forum Moderators: open

Message Too Old, No Replies

iframe & ajax works only after an alert

         

portal76

11:34 pm on Mar 22, 2007 (gmt 0)

10+ Year Member



HI all,
the following code shows a strange behavior to me.
I have created an iframe whose source is empty.
I need to fill this iframe at runtime using ajax. Everything seems to work fine ONLY if I use an alert like shown in the code below.

Any clue?
Thank you

<iframe id="frame_iview" src=""> </iframe>
...

try{
var obj = document.getElementById("frame_iview");
if (obj.contentWindow)
{
alert("1"); // if I remove this it won't work
obj.contentWindow.document.body.innerHTML = xmlHttp.responseText;
}
else if (obj.contentDocument){ obj.contentDocument.body.innerHTML = xmlHttp.responseText;
}
}
catch (ex){
}

tedster

6:57 pm on May 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello portal76, and welcome to the forums. Sorry your post went so long without a reply.

The alert() gives the ajax some extra time to execute - and it probably is time that is the issue here, You can accomplish the same thing with setTimeout() and the script would read more intuitively.