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
LVL 7
minnirokAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bubbledragonCommented:
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;

0
Michel PlungjanIT ExpertCommented:
If it is a timing issue, try this:


strBody = "";
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.
    setTimeout('resetIt()',100)
}
function resetIt() {
  document.getElementById("e_body").contentWindow.document.body.innerHTML = strBody;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
minnirokAuthor Commented:
@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
0
Michel PlungjanIT ExpertCommented:
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
0
minnirokAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.