If user selection is null, editor1doc.selection.createRange().htmlText fails in Firefox?

  •  06-13-2007, 6:44 PM

    If user selection is null, editor1doc.selection.createRange().htmlText fails in Firefox?

    The following Javascript code works fine in IE, but in Firefox, if the user has not actually highlighted any content in the editor, the 'createRange()' statement appears to just fail (the Javascript function ends without the alert after the statement appearing).   Is there a way to test for a null user selection in Firefox so that I can just PasteHTML(Date()) instead of my PasteHTML(selectedhtml + Date()) in that case?
     
    function CE_AddDateTime()
    {
       //  Paste current date/time into current cursor-point of editor.
       var editor1 = document.getElementById('<%=Editor1.ClientID%>');
       alert("DEBUG: CE_AddDateTime, after definition of editor1");
       var editor1doc = editor1.GetDocument();
       alert("DEBUG: CE_AddDateTime, after definition of editor1doc");
       var selectedhtml = editor1doc.selection.createRange().htmlText;
       alert("DEBUG: CE_AddDateTime, after definition of selectedhtml");
       editor1.PasteHTML(selectedhtml + Date());
    }
View Complete Thread