designMode not working with IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Rivers

    designMode not working with IE

    Hi,

    I'm trying to build a web page where the user can insert text
    dinamically. When the user hits a button, a new text box is created and
    the user can insert text into it.

    It's working nice with Firefox 1.0, but it's not working with IE
    6.0.2800.1106 (W2K SP4)

    function addText() {
    doc = document.getEle mentById("deskt op");

    myIframe = document.create Element("iframe ");
    myIframe.id = "editFrame" ;
    myIframe.name = "editFrame" ;
    myIframe.style. border = "1px dotted";
    myIframe.style. position = "relative";

    doc.appendChild (myIframe);

    if(document.all ) {
    document.editFr ame.document.de signMode = 'On';
    } else {
    document.getEle mentById("editF rame").contentD ocument.designM ode =
    "on";
    }
    }

    I did a test putting it inside an static page (below) and it worked.

    <HTML>
    <HEAD></HEAD>
    <BODY>
    <IFRAME NAME="editFrame "></IFRAME>
    <SCRIPT>
    document.editFr ame.document.de signMode = 'On';
    </SCRIPT>
    </BODY>
    </HTML>

    So, is it possible to do it on the fly? Any help?

    TIA,

    Bob

  • Martin Honnen

    #2
    Re: designMode not working with IE



    Bob Rivers wrote:

    [color=blue]
    > I'm trying to build a web page where the user can insert text
    > dinamically. When the user hits a button, a new text box is created and
    > the user can insert text into it.[/color]

    If you want a text box then use the DOM to create a textarea element e.g.
    var textarea;
    if (document.creat eElement && (textarea =
    document.create Element('textar ea'))) {
    textarea.name = 'textareaName';
    textarea.rows = 5;
    textarea.cols = 40;
    someElement.app endChild(textar ea);
    }
    [color=blue]
    > It's working nice with Firefox 1.0, but it's not working with IE
    > 6.0.2800.1106 (W2K SP4)[/color]

    So what happens with IE, do you get an error message?

    It might be that you need to make sure that some document is in the
    iframe before you try to script the document and its designMode property.

    The following example here creates the iframe without problems with
    Firefox 1.0, Netscape 7.2, and IE 6:

    <html lang="en">
    <head>
    <title>dynamica lly creating an editable iframe with Mozilla and
    IE/Win</title>
    <script type="text/javascript">
    function createEditableI frame (iframeName, parentElement, initialContent) {
    var iframeElement;
    if (document.creat eElement && (iframeElement =
    document.create Element('iframe '))) {
    iframeElement.i d = iframeName;
    iframeElement.n ame = iframeName;
    iframeElement.w idth = '100%';
    iframeElement.h eight = '200';
    parentElement.a ppendChild(ifra meElement);
    var iframeWin = window.frames[iframeName];
    if (iframeWin) {
    iframeWin.docum ent.open();
    iframeWin.docum ent.write(initi alContent);
    iframeWin.docum ent.close();
    iframeWin.docum ent.designMode = 'on';
    iframeWin.focus ();
    }
    }
    }

    window.onload = function (evt) {
    createEditableI frame(
    'editFrame',
    document.body,
    [ '<html lang="en">',
    '<head>',
    '<title>exampl e content<\/title>',
    '<\/head>',
    '<body>',
    '<p>Try to edit this content.<\/p>',
    '<\/body>',
    '<\/html>'
    ].join('\r\n')
    );
    };
    </script>
    </head>
    <body>

    <h1>dynamical ly creating an editable iframe with Mozilla and IE/Win</h1>

    </body>
    </html>

    --

    Martin Honnen

    Comment

    • Adam Ratcliffe

      #3
      Re: designMode not working with IE

      Hi Bob

      You might also want to take a look at HTMLArea,
      http://www.interactivetools.com/free.../htmlarea.html. It provides
      some extended editing features.

      Cheers
      Adam

      Comment

      • Bob Rivers

        #4
        Re: designMode not working with IE

        Hi,

        Thanks. It worked.

        Bob
        [color=blue]
        > It might be that you need to make sure that some document is in the
        > iframe before you try to script the document and its designMode[/color]
        property.[color=blue]
        >
        > The following example here creates the iframe without problems with
        > Firefox 1.0, Netscape 7.2, and IE 6:
        >
        > <html lang="en">
        > <head>
        > <title>dynamica lly creating an editable iframe with Mozilla and
        > IE/Win</title>
        > <script type="text/javascript">
        > function createEditableI frame (iframeName, parentElement,[/color]
        initialContent) {[color=blue]
        > var iframeElement;
        > if (document.creat eElement && (iframeElement =
        > document.create Element('iframe '))) {
        > iframeElement.i d = iframeName;
        > iframeElement.n ame = iframeName;
        > iframeElement.w idth = '100%';
        > iframeElement.h eight = '200';
        > parentElement.a ppendChild(ifra meElement);
        > var iframeWin = window.frames[iframeName];
        > if (iframeWin) {
        > iframeWin.docum ent.open();
        > iframeWin.docum ent.write(initi alContent);
        > iframeWin.docum ent.close();
        > iframeWin.docum ent.designMode = 'on';
        > iframeWin.focus ();
        > }
        > }
        > }
        >[/color]

        Comment

        Working...