Nested links using PasteHTML()

  •  07-20-2009, 5:15 PM

    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\>");  

     

View Complete Thread