Click to See Complete Forum and Search --> : Mshtml


marko_one
10-13-2003, 06:29 PM
Hi All,
I am trying to develop a rich text box using MSHTML, and so use contenteditable to be able to use the rich text features to insert into my site. The only problem is that I want to be able to take out the <p>, </p> tags when pressing enter and replace them with a <br> tag. This injjecting a <p>, </p> tag seems to be the default action when using this feature of MSHTML.

There is a way round this problem, using a function like the following :

el.frameWindow.document.onkeydown = function () {
if (el.frameWindow.event.keyCode == 13) { // ENTER
var sel = el.frameWindow.document.selection;
if (sel.type == "Control")
return;

var r = sel.createRange();
r.pasteHTML("<br>");
el.frameWindow.event.cancelBubble = true;
el.frameWindow.event.returnValue = false;

r.select();
r.moveEnd("character", 1);
r.moveStart("character", 1);
r.collapse(false);

return false;
}
};

el.frameWindow.document.onkeypress =
el.frameWindow.document.onkeyup = function () {
if (el.frameWindow.event.keyCode == 13) { // ENTER
el.frameWindow.event.cancelBubble = true;
el.frameWindow.event.returnValue = false;
return false;
}
};


This code will allows me to press enter and give me a line break, but it has the problem that when I attempt to use a bulleted list then the whole text section tabs in and is effectively contained within the <UL>, </UL> tags. I got this bit of code from http://dbforums.com/arch/195/2003/1/509584

As I am not that much of an expert in DHTML, I did some googleing to get some answers, and if I'm completely honest I'm not really sure of what is going on in that bit of code above.

I think it has something to do with the order of events, but that is not clear to me?

can anybody help me out with this tough call??

thanks

marko.

lillu
10-18-2003, 05:02 AM
Just a remark.

Insert <br /> tags instead of <br> Even empty elements must have a closing / to be well-formed.