Javascript Error when call "editor.ExecCommand('InsertDocument');"

Last post 01-25-2016, 5:33 AM by Kenneth. 10 replies.
Sort Posts: Previous Next
  •  01-18-2016, 9:32 PM 82222

    Javascript Error when call "editor.ExecCommand('InsertDocument');"

    error occure when I use javascript to call "editor.ExecCommand('InsertDocument');"

     

    in chrom it return:

    Failed to execute 'insertNode' on 'Range': The node to be inserted is a 'A' node, which may not be inserted here

     

    in IE:

    Object doesn't support property or method 'addEventListener'

     

    How to fix both of the browser javascript error?

     

  •  01-18-2016, 11:43 PM 82244 in reply to 82222

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    I sorry that I missing some words

    I am using StandardDialog 

    and I trace the porblem of chrom because of running "editor.ExecCommand('new')" before "editor.ExecCommand('InsertDocument')"

    How to solve by chrom if not running "editor.ExecCommand('new')" to empty the content before running other command?

     

    and I cannot trace the problem of IE

    It still has error "Object doesn't support property or method 'addEventListener'".

  •  01-19-2016, 8:49 AM 82261 in reply to 82244

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    Hi,

     

    Please try the example page below, does it work for you?

     

    1. <%@ Page Language="C#" ValidateRequest="false" %>  
    2.   
    3. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>  
    4. <html>  
    5. <head>  
    6.     <title>example </title>  
    7. </head>  
    8. <body>  
    9.     <form id="Form1" runat="server">  
    10.         <CE:Editor ID="Editor1" runat="server" UseStandardDialog="true">  
    11.         </CE:Editor>  
    12.         <input type="button" value="custom command" onclick="myCommand()" />  
    13.     </form>  
    14. </body>  
    15. </html>  
    16.   
    17. <script type="text/javascript">  
    18.     function myCommand()  
    19.     {  
    20.         var editor1 = document.getElementById('<%= Editor1.ClientID%>');  
    21.         editor1.ExecCommand("InsertDocument");  
    22.     }  
    23. </script>  
     

    Regards,

     

    Ken 

  •  01-19-2016, 10:56 PM 82267 in reply to 82261

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    thanks for reply

    it cannot solve the errors because it needs to run "editor.ExecCommand('new')" before to clear the editor content

    because need to use following functions to get the selected file path

     

     

    1. function editor_function() {  
    2.          var editor = document.getElementById('<%=editor.ClientID%>');  
    3.          editor.FocusDocument();  
    4.          editor.ExecCommand('new'); // hide this will be fine but cannot because need to clear the content. for IE still have other error if hiding this  
    5.            
    6.          InputURL();                              
    7.   
    8.          editor.ExecCommand('InsertDocument');  
    9.      }  
    10.   
    11.      function InputURL() {                  
    12.          var editor = document.getElementById('<%=editor.ClientID%>');  
    13.          var editdoc = editor.GetDocument();  
    14.          var links = editdoc.getElementsByTagName("a");  
    15.   
    16.          var link_data = "";  
    17.          for (var i = links.length - 1; i >= 0; i--) {  
    18.              if (links[i].href != "") {  
    19.                  link_data = links[i].href;  
    20.                  break;  
    21.              }  
    22.          }  
    23.   
    24.          if (link_data != "") {  
    25.              document.getElementById('file_path_textfield').value = link_data;  
    26.          }  
    27.          else {  
    28.              setTimeout(InputURL, 500);  
    29.          }  
    30.      }   

     

  •  01-20-2016, 6:33 AM 82276 in reply to 82267

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    Hi,

     

    can you provide the full example code what you are testing? are you trying the image selector demo page?

     

    Regards,

     

    ken 

  •  01-21-2016, 3:11 AM 82295 in reply to 82276

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

     Dear Kenneth,

     

    Here are the codes:

    1. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>    
    2.         
    3.     <html>    
    4.         <head>    
    5.             <title></title>    
    6.                 
    7.     <style type='text/css'>    
    8.     body     
    9.     {    
    10.         margin: 0px;     
    11.         padding: 0px;    
    12.     }    
    13.     </style>             
    14.        
    15.             <script language="javascript">  
    16.                 function callInsertFile() {  
    17.                     var editor = document.getElementById('<%=editor.ClientID%>');  
    18.                     editor.FocusDocument();  
    19.                     setTimeout(function() { delay_editor_function(editor) }, 500);  
    20.                     return false;  
    21.                 }  
    22.   
    23.                 function delay_editor_function(editor) {  
    24.                     editor.ExecCommand('new');  
    25.   
    26.                     InputURL();  
    27.   
    28.                     editor.ExecCommand('InsertDocument');  
    29.                 }  
    30.   
    31.                 function InputURL() {  
    32.                     var editor = document.getElementById('<%=editor.ClientID%>');  
    33.                     var editdoc = editor.GetDocument();  
    34.                     var links = editdoc.getElementsByTagName("a");  
    35.   
    36.                     var link_data = "";  
    37.                     for (var i = links.length - 1; i >= 0; i--) {  
    38.                         if (links[i].href != "") {  
    39.                             link_data = links[i].href;  
    40.                             break;  
    41.                         }  
    42.                     }  
    43.   
    44.                     if (link_data != "") {  
    45.                         document.getElementById('select_path').value = link_data;  
    46.                     }  
    47.                     else {  
    48.                         setTimeout(InputURL, 500);  
    49.                     }  
    50.                 }           
    51.             </script>     
    52.         
    53.         </head>    
    54.         <body>        
    55.             <form id="Form1" runat="server">    
    56.                 <table border="0" cellpadding="0" cellspacing="0">    
    57.                     <tr>    
    58.                         <td>  
    59.                             <CE:Editor id="editor" runat="server" Width="1" Height="1" BackColor="White" BorderColor="White"></CE:Editor>    
    60.                               
    61.                             <input type="button" value="Browse" onclick="return callInsertFile();" id="file_path_btn" style="width:150px;height:30px;"/>  
    62.                             <br />        
    63.                             <input type="text" id="select_path" value="" style="width:500px;" />  
    64.                         </td>    
    65.                     </tr>    
    66.                 </table>    
    67.             </form>    
    68.         </body>    
    69.     </html>    
     

    P.S.

    chrom return error:

    Uncaught HierarchyRequestError: Failed to execute 'insertNode' on 'Range': The node to be inserted is a 'A' node, which may not be inserted here. 

     

    IE return error:

    Object doesn't support property or method 'addEventListener' 

     

     

  •  01-21-2016, 7:45 AM 82296 in reply to 82295

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    Hi,

     

    Please try the example page below, does it work for you?

     

    1. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>  
    2. <%@ Page Language="C#"%>  
    3. <html>  
    4. <head>  
    5.     <title>ASP.NET WYSIWYG Editor - Use CuteEditor as a document selector</title>  
    6.     <style>  
    7.         body {   
    8.         text-align: center;   
    9.         margin-top:20px  
    10.         }  
    11.         .demo {   
    12.         text-align: left;   
    13.         width: 700px;  
    14.         border:solid 5px #CBCAC6;  
    15.         background-color:#fbfbfb;  
    16.         padding: 30px 30px 50px 30px;   
    17.         font-family:Segoe UI, Arial,Verdana,Helvetica,sans-serif;  
    18.         font-size: 100%;  
    19.         margin: 0 auto;   
    20.         }   
    21.     </style>  
    22. </head>  
    23. <body>  
    24.     <form id="Form1" runat="server">  
    25.         <div class="demo">  
    26.             <h3>  
    27.                 Use CuteEditor as a document selector</h3>  
    28.             <p>  
    29.                 This example demonstrates how to use CuteEditor as a document selector.  
    30.             </p>  
    31.             <br />  
    32.             <asp:TextBox ID="docFld" Width="300" runat="server" />  
    33.             <input type="button" value="Pick a file" onclick="callInsertImage()" id="Change"  
    34.                 runat="server" name="Change">  
    35.             <CE:Editor id="Editor1" runat="server" Width="1" Height="1" AutoConfigure="None"  
    36.                 ShowHtmlMode="False" ShowPreviewMode="False" EnableContextMenu="false" ShowGroupMenuImage="False"  
    37.                 ShowBottomBar="False" BackColor="White" BorderColor="White">  
    38.             </CE:Editor>  
    39.         </div>  
    40.     </form>  
    41.   
    42.     <script language="javascript">   
    43.       
    44.      function callInsertImage()    
    45.     {    
    46.             var editor1 = document.getElementById('<%=Editor1.ClientID%>');  
    47.             var editdoc = editor1.GetDocument();    
    48.             editdoc.body.innerHTML="";  
    49.             editor1.ExecCommand('insertdocument');  
    50.             InputURL();  
    51.             document.getElementById("<%=docFld.ClientID%>").focus();   
    52.     }     
    53.       
    54.     function InputURL()  
    55.     {   
    56.         var editor1 = document.getElementById('<%=Editor1.ClientID%>');  
    57.         var editdoc = editor1.GetDocument();    
    58.         var links = editdoc.getElementsByTagName("a");         
    59.         if(links.length>0&&links[links.length-1].href!="")    
    60.         {   document.getElementById("<%=docFld.ClientID%>").value = links[links.length-1].href;         
    61.         }    
    62.         else  
    63.         {  
    64.             setTimeout(InputURL,500);   
    65.         }     
    66.     }        
    67.     </script>  
    68.   
    69. </body>  
    70. </html>  
     

    Regards,

     

    Ken 

  •  01-21-2016, 9:27 PM 82303 in reply to 82296

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    Thank you for reply

    the differnt with your code is using  "editdoc.body.innerHTML="";" to clear the content

    it works on chrom

     

    However error occure on FireFox now:

    InvalidNodeTypeError: The supplied node is incorrect or has an incorrect ancestor for this operation.

     

    and still have error on IE:

    Object doesn't support property or method 'addEventListener'

     

    P.S.

    I am using StandardDialog

     

  •  01-22-2016, 9:00 AM 82320 in reply to 82303

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    try change code editdoc.body.innerHTML="";  to editdoc.body.innerHTML=" ";  it will fix the firefox and IE issue.

     

    Regards,

     

    ken 

     

  •  01-24-2016, 10:10 PM 82324 in reply to 82320

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    it can solve the error in firefox

    However IE still have error with "Object doesn't support property or method 'addEventListener'"  

  •  01-25-2016, 5:33 AM 82341 in reply to 82324

    Re: Javascript Error when call "editor.ExecCommand('InsertDocument');"

    what ie version you are testing?
View as RSS news feed in XML