<body>
<a href="javascript:doEdit(frmMain.document);">editIframe</a>
<a href="javascript:doEdit(document);">editBody</a>
<br>
<a href="javascript:chgSelFont(frmMain.document);">editBody</a>
<a href="javascript:formatBody(frmMain.document);">formatBody</a>
<br>
<iframe id='frmMain' width="400" height="500"></iframe><script language='javascript'>
function doEdit(vDoc){
    vDoc.body.contentEditable = true;    
}
function chgSelFont(vDoc){
   alert(vDoc.selection.createRange().text);
}
function formatBody(vDoc){
var s ;
//s=vDoc.body.innerHTML;
s = vDoc.selection.createRange();
// alert(vDoc.body.innerHTML);   
//vDoc.body.innerHTML='<font color=red>HELLO</color>';
//vDoc.body.text = 'darkred';//text color
s.pasteHTML('<font color=red>'+s.text+'</font>');
}</script>
</body>