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

  •  06-14-2007, 10:13 AM

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

    rockford,
     
    The following code will only work in IE.
     
    var selectedhtml = editor1doc.selection.createRange().htmlText;
    Only IE supports htmlText method.
     
    Replace the above code with the following code:
     
    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();

       var editdoc=editor1.GetDocument();  
       var editwin = editor1.GetWindow();

       alert("DEBUG: CE_AddDateTime, after definition of editordoc");
       var selectedhtml = getSelectedHTML();

       alert("DEBUG: CE_AddDateTime, after definition of selectedhtml");
       editor1.PasteHTML(selectedhtml + Date());

     

        function getSelectedHTML(){
          var rng=null,html="";

          if (document.selection && document.selection.createRange){
            rng=editdoc.selection.createRange();
            html=rng.htmlText||"";
          }else if (window.getSelection){
            rng=editwin.getSelection();

            if (rng.rangeCount > 0 && window.XMLSerializer){
              rng=rng.getRangeAt(0);
              html=new XMLSerializer().serializeToString(rng.cloneContents());
            }
          }
          return html;
        }
    }


     


    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

View Complete Thread