Nested links using PasteHTML()

Last post 07-21-2009, 2:47 AM by rrowles2000. 2 replies.
Sort Posts: Previous Next
  •  07-20-2009, 5:15 PM 54138

    Nested links using PasteHTML()

    Hi,
     
    Sorry if this is a dumb question! I couldn't find an answer to this in the forum but to cut a long story short, when I use pasteHTML to paste a link into the editor from my custom button. I get nested links. Is there any way of stopping this? Thanks in advance. Rich.
     
    I've got masses of code but basically it goes like this;

    1) Editor starts of in preview mode with "this is a paragraph"

    2) I click my custom button which does;

    1.          if(command=="MyInsertLink")   
    2.          {   
    3. var sel = editor1.GetSelection();   
    4. var r = sel.createRange();   
    5. selFromEditor = r.htmlText;            
    6. if(selFromEditor != "")   
    7.     {                
    8.         document.getElementById("EditorDiv").style.visibility = "hidden";   
    9.         document.getElementById("insertLinkBox").style.visibility = "visible";   
    10.         //document.getElementById("html1").value = h;   
    11.     }      
    12. return true;                       
    13.          }    
     3) My code then does some ajax stuff and uses .pasteHTML to paste a link in to the editor to replace the 'current selection'.
    If the selection is not already a link, it works.
     
    For example
     
    <h1>This is 9</h1>
    <p>This is a paragraph</p>
     
    becomes
     
    <h1>This is 9</h1>
    <p>This is a <a title="" href="http://cutesoft.net/files/add-button.gif">paragraph</a></p>
     
    but if I perform the same action again i get
     
    <h1>This is 9</h1>
    <p>This is a <a title="" href="http://cutesoft.net/files/add-button.gif"></a><a title="" href="http://cutesoft.net/files/add-button.gif">paragraph</a><a title="" href="http://cutesoft.net/files/add-button.gif"></a></p>
     
    The code for pasting back in is;
    1. editor1.PasteHTML("\<a href=\""+linkFile+"\" title=\""+document.getElementById("linkTitle").value+"\"\>"+selFromEditor+"\</a\>");  

     

  •  07-21-2009, 2:33 AM 54145 in reply to 54138

    Re: Nested links using PasteHTML()

    **********CORRECTION **********
     
    For example
     
    <h1>This is 9</h1>
    <p>This is a paragraph</p>
     
    becomes
     
    <h1>This is 9</h1>
    <p>This is a <a title="" href="http://cutesoft.net/files/add-button.gif">paragraph</a></p>
     
    but if I perform the same action again i get
     
    <h1>This is 9</h1>
    <p>This is a <a title="" href="http://cutesoft.net/files/add-button.gif"></a><a title="" href="http://cutesoft.net/files/add-button.gif">paragraph</a><a title="" href="files/add-button.gif"></a></p>
  •  07-21-2009, 2:47 AM 54147 in reply to 54138

    Re: Nested links using PasteHTML()

    Answer was to call;
     
    editor1.ExecCommand("Unlink");
     
    //before
     
    editor1.PasteHTML(output);
     
    Maybe this will help someone else.
View as RSS news feed in XML