I am having problems with getting a HTML editor working. We are using “contentEditable” to implement it, however when any paragraph formatting option is done without contents selected, IE removes the ID from one of the divs in the page.
The problem repeats for me with the HTML,
- just save it to a file,
- then open it in IE
- enable jscript when asked
- push the button
- check you get two message boxes
- first one says “MainContents = object”
- second one says “MainContents = NULL”
I am using IE 6.0.2900.5512 with XP SP3
So does this repeat for you?
What is going on?
<html>
<head>
</head>
<body id="BODY">
<div contentEditable="true" id="EDITBOX">
</div>
<div id="MAINCONTENTS" unselectable="on">
<button title="Ordered List" unselectable="on"
onclick='alert("MainContents = " + document.getElementById("MAINCONTENTS"));
document.execCommand("InsertOrderedList");
alert("MainContents = " + document.getElementById("MAINCONTENTS"));
'>
Push Me
</button>
</div>
</body>
</html>
<script type="text/javascript">
document.getElementById("EDITBOX").focus();
</script>
Background
I work for an ISV that sell software to corporations, at present all our customers use IE and there is no market depend to support other browsers. I have been told to implement an HTML editor using contentEditable. All the formatting options are based on document.execCommand(), e.g. document.execCommand(“bold”);
Due to licensing restrictions (LGPL is not liked) and/or cost it is very hard to get approval to use a 3rd party HTML editor. It took us a log time just to be allowed to use jquery.
I have the editor working apart from the case of paragraph formatting commands when the user does not have any items selected. The HTML I posted is a small bit of HTML I wrote to reproduce the problem I am having.
see also http://www.maconstateit.net/tutorials/JSDHTML/JSDHTML12/jsdhtml12-02.htm and
Risk of using contentEditable in IE
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…