designMode not working with IE

B

Bob Rivers

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.getElementById("desktop");

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

doc.appendChild(myIframe);

if(document.all) {
document.editFrame.document.designMode = 'On';
} else {
document.getElementById("editFrame").contentDocument.designMode =
"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.editFrame.document.designMode = 'On';
</SCRIPT>
</BODY>
</HTML>

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

TIA,

Bob
 
M

Martin Honnen

Bob Rivers wrote:

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.

If you want a text box then use the DOM to create a textarea element e.g.
var textarea;
if (document.createElement && (textarea =
document.createElement('textarea'))) {
textarea.name = 'textareaName';
textarea.rows = 5;
textarea.cols = 40;
someElement.appendChild(textarea);
}
It's working nice with Firefox 1.0, but it's not working with IE
6.0.2800.1106 (W2K SP4)

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>dynamically creating an editable iframe with Mozilla and
IE/Win</title>
<script type="text/javascript">
function createEditableIframe (iframeName, parentElement, initialContent) {
var iframeElement;
if (document.createElement && (iframeElement =
document.createElement('iframe'))) {
iframeElement.id = iframeName;
iframeElement.name = iframeName;
iframeElement.width = '100%';
iframeElement.height = '200';
parentElement.appendChild(iframeElement);
var iframeWin = window.frames[iframeName];
if (iframeWin) {
iframeWin.document.open();
iframeWin.document.write(initialContent);
iframeWin.document.close();
iframeWin.document.designMode = 'on';
iframeWin.focus();
}
}
}

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

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

</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top