Link to home
Start Free TrialLog in
Avatar of minnirok
minnirok

asked on

strange behavior with designMode under IE

I have an iframe.. I want to toggle designMode on and off. I have a function to do it like:

function ToggleDesignMode(bOn)
{
    // Save the contents of the iFrame..
    var strBody = document.getElementById("e_body").contentWindow.document.body.innerHTML;

    // Toggle design mode on/off.
    document.getElementById("e_body").contentWindow.document.designMode = bOn ? 'on' : 'off';

    // Set the contents back again.
    document.getElementById("e_body").contentWindow.document.body.innerHTML = strBody;
}

This whole function was created in an attempt to get IE to work.. If I just toggle the designMode attribute, in IE all the contents of the iframe will be deleted. So I have this function to store the contents while the mode is being toggled, then set the contents back afterwards. Is this really necessary?

This function actually fails when I try to set the body text back in the last call - oddly if I put an alert box right before it, it seems to work ok!? My guess is that there's some synchronization thing going on in which the mode hasn't been set yet or something?

Any help would be great, I've wasted a lot of time on this,
Thanks
Avatar of bubbledragon
bubbledragon

Hi, what the variable 'bOn' use for?

If your bOn passed 'on' or 'off', just assign the variable to designMode
document.getElementById("e_body").contentWindow.document.designMode = bOn;

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of minnirok

ASKER

@bubbledragon

I use the bOn just as a flag to say do I want design mode on or off - you're right, I could just instead pass the text 'on' or 'off' to the function, it would do the same thing.

@mplungian

I'll give that timing a try.

But why do we need to have this delay anyways - it's bizarre that IE needs to let some time elapse before executing that third call?

Thanks
Perhaps it is simply taking too many resources to be able to finish in the micro second it takes to go to the next statement
I guess so, it's so strange though. I can't find any information on it, I'd just like some reference that says:

    'setting designMode in IE takes a few milliseconds'

right now we're just guessing that's what's going on!

Thanks