YEP Sorry about the email. Hit the reply instead of group reply. Thanks for
staying with me.
if you can tell us what you're exactly trying to achieve then I
(or others) might provide you with some more information on how to
tackle the problem at a global level.
from original post -
"The intention here is to have a letter" (letterhead) "that can have
different borders clipart etc and the ability to select text and change the
various css properties or use exec Command to toggle them."
Also note that mixing innerHTML and innerText might provide unwanted
side-effects, since reading a BR via innerText, and writing innerText
afterwards, transforms the BR into CR/LF, which will render differently
on the screen.
Definately! I only used innerText to see if I got the same result as
obj.firstChild.data and didn't use it for assignment. I've been checking
both the DOM possibilities and innerHTML. Both have their challenges. AFAIK
innerText is not as widely supported as innerHTML and the DOM is fairly
safe.
Does Mozilla have the event object limitations of Netscape's DOM?
Does it support the createTextRange or createRange or createControlRange
methods?
Have you any ideas how to emulate IE execCommand in Mozilla?
Your code has another advantage in that it creates a separate textNode for
each character. I read that text nodes can be the target/srcElement of the
event object. Does the DOM have a separate event model? I am confused
probably about this.
Here is the basis of my last project. Sorry IE only.
in my original project changeSelection() is called from a controller with
options for bold, italic, underline, family, size, justification and color.
It is passed a parameter: changeSelection('Bold') which I switch in the
original function and pass to execCommand or another function.
e.g.
<a href="#" onclick = "changeSelection('Bold'); return false;"><b>B</b></a>
<a href="#" onclick = "changeSelection('Italic'); return
false;"><i>I</i></a>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD> <TITLE>Stationary Project Handlers</TITLE>
<style type=text/css>
<!--
#letter {
position:absolute;
top:20px;
width:45%;
height:90%;
background-color:#ffffcc;
color:navy;
padding:15px;
border:1px black solid;
}
-->
</style>
<script language="JavaScript">
function handleKey() {
if(event.keyCode == 8) {
letter.innerHTML =
letter.innerHTML.substring(0,letter.innerHTML.leng th-2) + '_';
event.returnValue = false;
}
if(event.keyCode == 13) {
letter.innerHTML =
letter.innerHTML.substring(0,letter.innerHTML.leng th-1);
letter.innerHTML += '<br>_';
event.returnValue = false;
}
}
function keyPress(){
letter.innerHTML =
letter.innerHTML.substring(0,letter.innerHTML.leng th-1);
var a = String.fromCharCode(event.keyCode);
if(!a) {alert("NO");return;}
letter.innerHTML += (a + '_');
}
function changeSelection() { // primitive just for example
// alert(letter.innerHTML); return; // for debugging
var range = document.selection.createRange();
var str=range.text;
range=document.body.createTextRange();
range.findText(str);
range.execCommand('Bold');
document.selection.empty();
}
document.onkeydown = handleKey;
document.onkeypress = keyPress;
document.onmouseup=changeSelection;
</script></HEAD>
<BODY><div id="letter">_</div></BODY></HTML>
Thanks again Jimbo