Insert Hyperlink - another button

Last post 05-30-2012, 1:16 AM by rajmohanp. 7 replies.
Sort Posts: Previous Next
  •  04-25-2012, 8:51 AM 73721

    Insert Hyperlink - another button

    Hi,

    I need to add another button in cute editor with same functionality like "Insert Hyperlink". When selecting the text or image in Cute Editor, then click that new button a popup window will open(refer the attached image "img1.jpg"). When click the image it redirects to the cute editor and added with "href" link(like Hyperlink). Can you pls give information at what are place(pages) do i need to change? And pls give code for doing this requirement?
     

     

    Thanks,
    P. Rajmohan
  •  04-27-2012, 2:03 PM 73724 in reply to 73721

    Re: Insert Hyperlink - another button

    Hi rajmohanp,
     
    1. Please refer to http://www.cutesoft.net/example/howto/AddDialogs/cs/create_a_custom_dialog.aspx , it shows you how to create your custom dialog.
     
    You can find the source code of this demo page in the editor download package "How to/AddDialogs/cs/create_a_custom_dialog.aspx" .
     
    2.  How to get the selection html code in the custom dialog?
     
    Use the code below
     
    function getSelectedHTML()      
    {         
          var rng=null,html="";            
          var editor1=Window_GetDialogArguments(window);
          // get the active editor document   
          var editdoc = editor1.GetDocument();   
      
          // get the active editor window    
          var editwin = editor1.GetWindow();      
          if (document.selection && document.selection.createRange)      
          {         
                rng=editdoc.selection.createRange();      
               if( rng.htmlText )       
               {       
                  html=rng.htmlText;       
               }       
               else if(rng.length >= 1)       
               {       
                  html=rng.item(0).outerHTML;       
               }      
          }      
          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;      
     
    Regards,
     
    Ken 
  •  05-09-2012, 7:04 AM 73746 in reply to 73724

    Re: Insert Hyperlink - another button

    Thanks for ur reply Kenneth...
  •  05-24-2012, 12:23 PM 73774 in reply to 73724

    Re: Insert Hyperlink - another button

    Hi Kenneth,
     
    When using the function, it's working correctly for me. But faced 1 issue.
     
    The Actual HTML code is,
     
     <img width="150" height="150" border="0" src="http://cutesoft.net/uploads/3c307013ae4c4e6d8a9bb730457f2c9c.jpg" alt=""  />
     
    But the value retrieved like,
     
    <img xmlns="http://www.w3.org/1999/xhtml" width="150" height="150" border="0" src="http://cutesoft.net/uploads/3c307013ae4c4e6d8a9bb730457f2c9c.jpg" alt="" /> 
     
    Actually,
     
     xmlnssrc_cetemp tag additionally adding....
     
    If suppose adding Anchor tag means, like <a href> but it is retrieved like href_cetemp additionally adding in it.
     
    Pls help how to avoid these tags when retrieving the Editor selected value.
     
    Thanks in advance,
    raj
  •  05-25-2012, 7:10 AM 73780 in reply to 73774

    Re: Insert Hyperlink - another button

    Hi rajmohanp,
     
    Can you show me the full steps to reproduce this issue?
     
    How can I get the additionally tag?
     
     
    Regards,
     
    Ken 
  •  05-25-2012, 8:14 AM 73781 in reply to 73780

    Re: Insert Hyperlink - another button

    Hi Kenneth,
     
    I just call the function "getSelectedHTML()" in "do_INSERT()" function for get the selected value in Editor.
     
    function do_INSERT()
            {
                var browserName = navigator.appName;  
                var editor=Window_GetDialogArguments(window);  
                var httpRequest;
                var FileData;
                var sGetSelectedValue = getSelectedHTML();
            alert(sGetSelectedValue);
                var sMainPath = "www.google.com";
                sImage=document.getElementById('FileName').value;
                if(trim(sGetSelectedValue) != "")
                {
                    FileData = "<div><a target='_blank' href='"+sMainPath+"'>"+trim(sGetSelectedValue)+"</a></div>";
                }
                else
                {
                    FileData = "<div><a target='_blank' href='"+sMainPath+"'>"+
                    "<img height='150' alt='' src='"+sImage+"' width='150' border='0' /><br>click here</a></div>";
                }
            alert(FileData);
                editor.PasteHTML(FileData) ;
               
                if(myWindow != "")
                {
                  myWindow.close();
                }
                Window_CloseDialog(window);
            } 
     
    Thanks,
    raj...
     
     
  •  05-28-2012, 7:56 AM 73786 in reply to 73781

    Re: Insert Hyperlink - another button

    hi rajmohanp,
     
    Please try the example below, it should work for you. The red code is what I add for the getSelectedHTML functioin.
     
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <CE:Editor ID="editor1" runat="server">
            </CE:Editor>
            <input type="button" value="show html" onclick="showHTML()" /><br />
            <asp:TextBox ID="t1" runat="server" TextMode="multiLine" Rows="10" Width="600"></asp:TextBox>
        </form>
    </body>
    </html>
    <script>
    function showHTML()
    {
       var t1=document.getElementById("<%= t1.ClientID %>");
       t1.innerHTML=getSelectedHTML();
    }
    function getSelectedHTML()      
    {         
          var rng=null,html="";            
          var editor1=document.getElementById("<%= editor1.ClientID %>");   
          // get the active editor document   
          var editdoc = editor1.GetDocument();   
      
          // get the active editor window    
          var editwin = editor1.GetWindow();    
          for(var i=0;i<editdoc.images.length;i++)
          {
              editdoc.images.item(i).removeAttribute("src_cetemp");
          }   
          if (document.selection && document.selection.createRange)      
          {         
                rng=editdoc.selection.createRange();      
               if( rng.htmlText )       
               {       
                  html=rng.htmlText;       
               }       
               else if(rng.length >= 1)       
               {       
                  html=rng.item(0).outerHTML;       
               }      
          }      
          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.split('xmlns="http://www.w3.org/1999/xhtml"').join('');      
    }   
    </script>
     
    Regards,
     
    Ken 
  •  05-30-2012, 1:16 AM 73787 in reply to 73786

    Re: Insert Hyperlink - another button

    Hi Kenneth ,
     
    WOW!!!. It's working great....
     
    Thank u very much Kenneth....
     
    by/-
    raj...
View as RSS news feed in XML