Re: Get the properties of the active object

  •  11-14-2010, 7:42 PM

    Re: Get the properties of the active object

    Hi AviPic,
     
    Please try the example below. Insert a image, add alt property ,select it and click the button.
     
    1. <%@ Page Language="C#" AutoEventWireup="true" %>  
    2.   
    3. <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5. <html>  
    6. <head>  
    7.     <title></title>  
    8. </head>  
    9. <body>  
    10.     <form id="form1" runat="server">  
    11.         <CE:Editor ID="editor1" runat="server">  
    12.         </CE:Editor>  
    13.         <input type="button" value="getALT" onclick="getALT()" />  
    14.     </form>  
    15. </body>  
    16. </html>  
    17.   
    18. <script>  
    19. function getALT()  
    20. {  
    21.        alert(getSelectedHTML());  
    22. }  
    23. function getSelectedHTML(){  
    24.     var editor1=document.getElementById("<%= editor1.ClientID %>");  
    25.       // get the active editor window  
    26.       var editwin = editor1.GetWindow();  
    27.   
    28.   
    29.       // get the active editor document  
    30.       var editdoc = editor1.GetDocument();  
    31.   
    32.       var rng=null,html="";   
    33.       if (document.selection && document.selection.createRange){  
    34.   
    35.         rng=editdoc.selection.createRange();  
    36.         html=rng.htmlText||"";  
    37.       }  
    38.       else if (window.getSelection){  
    39.       
    40.         rng=editwin.getSelection();  
    41.   
    42.         if (rng.rangeCount > 0 && window.XMLSerializer)  
    43.         {  
    44.           rng=rng.getRangeAt(0);  
    45.           for(var i=0;i<rng.startContainer.childNodes.length;i++)  
    46.           {  
    47.           if(rng.startContainer.childNodes[i].tagName=="IMG")  
    48.           {  
    49.            
    50.             html=rng.startContainer.childNodes[i].alt;  
    51.           }  
    52.         
    53.           }  
    54.           
    55.         }  
    56.       }  
    57.       
    58.       return html;  
    59.  }  
    60. </script> 
     
    Regards,
     
    Ken
View Complete Thread