Forum Moderators: open

Message Too Old, No Replies

Why alert() is needed for editing iFrame.document.body.innerHTML?

         

implemens

10:15 am on May 27, 2004 (gmt 0)



Hi,

I'm doing a WYSIWYG editor and using a iFrame for it. I want to fill the body of the iFrame with some data when the page is loaded.

Here's my Javascript:

function Init()
{
myiFrame.document.designMode = 'On';
var t='Hola campeones';
alert(t);
myiFrame.document.body.innerHTML = t;
}

My question is why this doesn't work when I take out the "alert(t)" statement?

Thanx in advance...

Purple Martin

11:11 pm on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think it's because the browser hasn't finished setting the designMode by the time the innerHTML is supposed to happen. You could try splitting the function into two, with the second one called by a setTimeout() in the first:

function Init()
{
myiFrame.document.designMode = 'On';
setTimeout("Init2()",100);
}
function Init2()
{
var t='Hola campeones';
myiFrame.document.body.innerHTML = t;
}

implemens

5:02 pm on Jun 1, 2004 (gmt 0)



Thank so much for your answer... It works.

It's really great! Hope you have a nice day!