(editor1doc.selection).type does not work in Firefox?

Last post 11-16-2007, 2:41 PM by Adam. 6 replies.
Sort Posts: Previous Next
  •  11-01-2007, 6:45 PM 34775

    (editor1doc.selection).type does not work in Firefox?

    The following Javascript function is called in the onclick event of an ASP.NET image button.   I put alert statements after each line to isolate where it is failing in Firefox for Windows 2.0.0.8.   In IE, this works fine and goes all the way through (pasting the string **FILE1** into the editor).   But, in Firefox, only the first three alerts show.   The fourth, which references (editor1doc.selection).type does not display, the function apparently ends at that point and the **FILE1** string is not pasted into the editor.
     
    Can you determine what is wrong?   Thanks.
     
    function CE_MarkEmbedObjectPosition()
    {
     alert("DEBUG: START CE_MARKEMBEDOBJECTPOSITION");
     // get the cute editor instance
     var editor1 = document.getElementById('');
     alert("DEBUG: CE_MARKEMBEDOBJECTPOSITION, after var editor1=" + editor1);
    var editor1doc = editor1.GetDocument();
    alert("DEBUG: CE_MARKEMBEDOBJECTPOSITION, after var editor1doc");
     alert("DEBUG:CE_MarkEmbedObjectPosition, (editor1doc.selection).type=" + (editor1doc.selection).type);
     if ((editor1doc.selection).type == "Text")
    {
     var selectedhtml = editor1doc.selection.createRange().htmlText;
    alert("DEBUG: CE_MarkEmbedObjectPosition, Text, selectedhtml=" + selectedhtml);
     editor1.PasteHTML(selectedhtml + "**FILE1**");
     }
     if ((editor1doc.selection).type == "None")
     {
     var selectedhtml = editor1doc.selection.createRange().htmlText;
     alert("DEBUG: CE_MarkEmbedObjectPosition, None, selectedhtml=" + selectedhtml);
     editor1.PasteHTML(selectedhtml + "**FILE1**");
     }
     alert("DEBUG:End of CE_MarkEmbedObjectPosition, gethtml=" + CE_getHTML());
     }
  •  11-05-2007, 11:11 AM 34820 in reply to 34775

    Re: (editor1doc.selection).type does not work in Firefox?

    Just reposting this as I see it has dropped well down the queue after several days while many newer posts have been answered.  Thanks.
  •  11-05-2007, 2:25 PM 34829 in reply to 34775

    Re: (editor1doc.selection).type does not work in Firefox?

    rockford:
    The following Javascript function is called in the onclick event of an ASP.NET image button.   I put alert statements after each line to isolate where it is failing in Firefox for Windows 2.0.0.8.   In IE, this works fine and goes all the way through (pasting the string **FILE1** into the editor).   But, in Firefox, only the first three alerts show.   The fourth, which references (editor1doc.selection).type does not display, the function apparently ends at that point and the **FILE1** string is not pasted into the editor.
     
    Can you determine what is wrong?   Thanks.
     
    function CE_MarkEmbedObjectPosition()
    {
     alert("DEBUG: START CE_MARKEMBEDOBJECTPOSITION");
     // get the cute editor instance
     var editor1 = document.getElementById('');
     alert("DEBUG: CE_MARKEMBEDOBJECTPOSITION, after var editor1=" + editor1);
    var editor1doc = editor1.GetDocument();
    alert("DEBUG: CE_MARKEMBEDOBJECTPOSITION, after var editor1doc");
     alert("DEBUG:CE_MarkEmbedObjectPosition, (editor1doc.selection).type=" + (editor1doc.selection).type);
     if ((editor1doc.selection).type == "Text")
    {
     var selectedhtml = editor1doc.selection.createRange().htmlText;
    alert("DEBUG: CE_MarkEmbedObjectPosition, Text, selectedhtml=" + selectedhtml);
     editor1.PasteHTML(selectedhtml + "**FILE1**");
     }
     if ((editor1doc.selection).type == "None")
     {
     var selectedhtml = editor1doc.selection.createRange().htmlText;
     alert("DEBUG: CE_MarkEmbedObjectPosition, None, selectedhtml=" + selectedhtml);
     editor1.PasteHTML(selectedhtml + "**FILE1**");
     }
     alert("DEBUG:End of CE_MarkEmbedObjectPosition, gethtml=" + CE_getHTML());
     }
     
    This htmlText Property is supported by IE only.
     
    htmlText Property - Retrieves the HTML source as a valid HTML fragment.
     
     
    Please use the following code:
     
     
     

    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

  •  11-05-2007, 2:47 PM 34834 in reply to 34829

    Re: (editor1doc.selection).type does not work in Firefox?

    Adam,
     
    Thanks, I see that I will need to do something differently later in the function.   However, as it stands now, because of the apparent failure of the statement which contains the reference to  (editor1doc.selection).type) , I can't get down to the point where htmlText is referenced.   Do I need to do that differently in Firefox (again, this all works fine in IE)?
  •  11-05-2007, 2:50 PM 34835 in reply to 34834

    Re: (editor1doc.selection).type does not work in Firefox?

    rockford:
    Adam,
     
    Thanks, I see that I will need to do something differently later in the function.   However, as it stands now, because of the apparent failure of the statement which contains the reference to  (editor1doc.selection).type) , I can't get down to the point where htmlText is referenced.   Do I need to do that differently in Firefox (again, this all works fine in IE)?
     
    editor1doc.selection is null in Firefox too.
     
    Can you just use the Code I wrote?
     
     

    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

  •  11-12-2007, 6:36 PM 35016 in reply to 34835

    Re: (editor1doc.selection).type does not work in Firefox?

    Adam, The first clause of the IF statement just drops out of the function without proceeding, but if you comment that out and start with the window.getSelection clause it seems to work fine, at least for the situations we are concerned with.   Thanks!

    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;
        }
  •  11-16-2007, 2:41 PM 35168 in reply to 35016

    Re: (editor1doc.selection).type does not work in Firefox?

    Use the following code:
     
     
     
      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 as RSS news feed in XML