You can do it in Netscape by using the document.getSelected() function call.
Here is an example of an HTML wysiwyg editor Im working on. It looks as though your doing a similar sort of thing.
<HTML>
<HEAD>
<TITLE>Capturing Key Presses</TITLE>
<style type="text/css">
#page { position: absolute; top: 80px; left: 16px; width: 484px; height: 316px; visibility: visible }
</style>
<script type="text/javascript" language="Javascript 1.2">
// Cross Browser WYSIWYG HTML editor using Javascript
// Author: Colin Bell
// Author email: colinb@gatewest.co.uk
// Date: 30th October 2001
// If you improve this script or add new features please send me a copy at colinb@gatewest.co.uk
// browser
var agt=navigator.userAgent.toLowerCase();
var is_major=parseInt(navigator.appVersion);
var is_minor=parseFloat(navigator.appVersion);
var is_nav =((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
var is_nav2=(is_nav && (is_major == 2));
var is_nav3=(is_nav && (is_major == 3));
var is_nav4=(is_nav && (is_major == 4));
var is_nav5=(is_nav && (is_major == 5));
var is_nav5up=(is_nav && (is_major >= 5));
var is_nav4down=(is_nav && (!is_nav5up));
var is_ie =(agt.indexOf("msie"

!= -1);
var is_ie3 =(is_ie && (is_major < 4));
var is_ie4 =(is_ie && (is_major == 4) && (agt.indexOf("msie 5.0"

==-1) );
var is_ie4up =(is_ie && (is_major >= 4));
var is_ie4down =(is_ie && (is_major <= 4));
var is_ie5 =(is_ie && (is_major == 4) && (agt.indexOf("msie 5.0"

!=-1) );
var is_ie5up =(is_ie && !is_ie3 && !is_ie4);
var is_5up=(is_ie5up || is_nav5up);
var is_hotjava=(agt.indexOf("hotjava"

!=-1);
var is_opera=(agt.indexOf("opera"

!= -1);
var is_webtv=(agt.indexOf("webtv"

!= -1);
var is_win =( (agt.indexOf("win"

!=-1) || (agt.indexOf("16bit"

!=-1) );
var is_mac =(agt.indexOf("mac"

!=-1);
var vIE55Win=navigator.appVersion.toLowerCase().indexOf("msie 5.5"

!=-1 && is_win;
var vIE4Win=is_ie4 && is_win;
var vIE4Mac=is_ie4 && is_mac;
var normText = "";
var styledText = "";
//the string that is currently selected
var selectedStr = "";
var isBold = false;
var isItalic = false;
// switch bold on and off
function isBoldToggle() {
// if the user has something selected we bold that
if (selectedStr){modSelectedText("B"

;return;}
// otherwise we turn bold on
else if (isBold == false){isBold = true; alert("Bold On"

;}
else if (isBold == true){
isBold = false; alert("Bold Off"

;
normText = normText + "<B>" + styledText + "<\/B>";
styledText = "";
}
}
// switch italics on and off
function isItalicToggle() {
if (selectedStr){modSelectedText("I"

;return;}
// otherwise we turn italics on
else if (isItalic == false){isItalic = true; alert("isItalic On"

;}
else if (isItalic == true){
isItalic = false; alert("isItalic Off"

;
normText = normText + "<I>" + styledText + "<\/I>";
styledText = "";
}
}
//This will show you your selected text
function display() {
if (document.getSelection) selectedStr = document.getSelection();
else if (document.selection) selectedStr = document.selection.createRange().text;
selectedStr.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," "

;
document.myForm.myArea.value = selectedStr;
}
// this is the event that captures the selected text
if (window.Event)
document.captureEvents(Event.MOUSEUP);
document.onmouseup = display;
// this function will modify the selected text
function modSelectedText(myTag)
{
var myInfo = fgetDivText("page"

;
pattern = "/" + selectedStr +"/ig;";
pattern = eval(pattern);
myInfo = myInfo.replace(pattern,"<"+ myTag +">" + selectedStr +"<\/"+ myTag +">"

;
fWriteDiv("page",myInfo);
normText = myInfo;
document.GENERATE.typeHere.value = myInfo;
}
//this routine filters out mistakes and useless tags
function cleanUp(whatString)
{
var pattern = /<I><\/I>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<B><\/B>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<\/I><\/I>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<\/B><\/B>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<B<\/B>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<B<B>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<B><B>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<I><I>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<I<I>/ig;
var whatString = whatString.replace(pattern,""

;
var pattern = /<I<\/I>/ig;
var whatString = whatString.replace(pattern,""

;
return whatString;
}
// during the delete if we hit a tag, we have to find out what it is
// this will hunt through and returns the tag found
function deleteTag(whatString, endChar)
{
// duplicate the string for mods
for (i=0;i<whatString.length;i++){
//if we find the start tag we capture it
if (whatString.charAt(whatString.length - i) == "<"

{
// select the tag
mySubString = whatString.substring(whatString.length - i,endChar + 1)
// delete the tag
myInfo = whatString.substring(0,whatString.length - i)
// write back the string with the tag removed
fWriteDiv("page",myInfo)
document.GENERATE.typeHere.value = myInfo;
// if its not an end tag we delete again
return mySubString;
}
}
}
// if it was the backSpace we cancel the event or else it try to go back in history
// This routine handles going back (delete)
function checkBack(e){
var myInfo = fgetDivText("page"

;
if (is_nav4){keyPressed = String.fromCharCode(e.which); code = e.which;}
else if (is_ie4up){keyPressed = String.fromCharCode(window.event.keyCode);code = window.event.keyCode;}
// if it was the backSpace we cancel the event or else it will try to go back in history
if (window.event && window.event.keyCode == 8) { // try to cancel the backspace
//avoid a out of memory error by not going to far back
if (myInfo.length < 0){return;}
// Now to handle the tags
// if bold and italics are off
if ((isBold == false) && (isItalic== false)){
// check to see if we are on a tag (ie <\/b>)
if (myInfo.charAt(myInfo.length - 1) == ">"

{
myTag = deleteTag(myInfo, myInfo.length - 1);
myInfo = fgetDivText("page"

;
myInfo = myInfo.substring(0,myInfo.length - 1)
// add the tag back on
myInfo = myInfo + myTag
}
else {myInfo = normText.substring(0,normText.length - 1)}
normText = myInfo
}
// if bold is on and italics are off
else if ((isBold == true) && (isItalic == false)) {
styledText = styledText.substring(0,styledText.length - 1)
myInfo = normText + "<B>" + styledText + "<\/B>";
}
// if bold is on and italics are on
else if ((isBold == true) && (isItalic == true)) {
styledText = styledText.substring(0,styledText.length - 1)
myInfo = normText + "<B><I>" + styledText + "<\/I><\/B>";
}
// if bold is off and italics are on
else if ((isBold == false) && (isItalic == true)) {
styledText = styledText.substring(0,styledText.length - 1)
myInfo = normText + "<I>" + styledText + "<\/I>";
}
// cleanup the information
myInfo = cleanUp(myInfo);
normText = myInfo;
//write the final code
fWriteDiv("page",myInfo)
document.GENERATE.typeHere.value = myInfo;
window.event.cancelBubble = true;
window.event.returnValue = false;
return false;
}
}
//If keycode = 39 Then
//' right arrow key was pressed
//Picture1.Move Picture1.Left - 100
//End If
//If keycode = 37 Then
//' left arrow key was pressed
//Picture1.Move Picture1.Left + 100
//End If
//If keycode = 38 Then
//' up arrow key was pressed
//Picture1.Move Picture1.Top + 100
//End If
//If keycode = 40 Then
//' down arrow key was pressed
//Picture1.Move Picture1.Top - 100
function updateMe(e)
{
var myInfo = fgetDivText("page"

;
//empty out the selection
//selectedStr ="";
if (is_nav4){keyPressed = String.fromCharCode(e.which); code = e.which;}
else if (is_ie4up){keyPressed = String.fromCharCode(window.event.keyCode);code = window.event.keyCode;}
// if was an enter we make it a <br>
if (code==13){keyPressed = "<BR>";}
// if it was the backSpace we cancel the event or else it will try to go back in history
if (window.event && window.event.keyCode == 8) { // try to cancel the backspace
window.event.cancelBubble = true;
window.event.returnValue = false;
return false;
}
// convert to HTML
if (keyPressed == "<"

{ keyPressed = "<"};
if (keyPressed == ">"

{ keyPressed = ">"};
if (keyPressed == "&"

{ keyPressed = "&"};
// if bold and italics are off
if ((isBold == false) && (isItalic== false)){ normText += keyPressed;myInfo = normText;}
// if bold is on and italics are off
else if ((isBold == true) && (isItalic == false)) { styledText += keyPressed;myInfo = normText + "<B>" + styledText + "<\/B>";}
// if bold is on and italics are on
else if ((isBold == true) && (isItalic == true)) {styledText += keyPressed;myInfo = normText + "<B><I>" + styledText + "<\/I><\/B>";}
// if bold is off and italics are on
else if ((isBold == false) && (isItalic == true)) { styledText += keyPressed;myInfo = normText + "<I>" + styledText + "<\/I>";}
fWriteDiv("page",myInfo)
document.GENERATE.typeHere.value = myInfo;
}
function fWriteDiv(inName,inText){
var tDoc;
if(is_nav4){
eval("tDoc=document." + inName + ".document"

;
tDoc.open();
tDoc.write(inText);
tDoc.close();
}
if (is_ie4){document.all[inName].innerHTML=inText; }
if (is_5up){document.getElementById(inName).innerHTML=inText; }
}
function fgetDivText(inName){
var tDoc;
if(is_nav4){
eval("tDoc=document." + inName + ".document"

;
tDoc.open();
inText = tDoc.HTML;
tDoc.close();
}
if (is_ie4){inText = document.all[inName].innerHTML; }
if (is_5up){inText = document.getElementById(inName).innerHTML; }
return inText
}
</script>
</HEAD>
<body onkeypress ="updateMe();" onkeyDown ="checkBack();">
<a href="#" onMouseUp="javascript:isBoldToggle()">Bold</A> <a href="#" onMouseUp="javascript:isItalicToggle()">Italic</A>
<DIV class="testarea" id="page"></DIV>
<form name="GENERATE">
<BR><BR><BR><BR><BR><BR><textarea style="displays" rows=10 cols=50 name="typeHere" WRAP="Yes"></textarea>
</form>
<P><FORM NAME="myForm">
<TEXTAREA NAME="myArea" COLS="40" ROWS="4"></TEXTAREA>
</FORM></P>