views:

253

answers:

1

I have added a custom file selector plugin for FCKeditor and inserting of a new link works fine. The problem is that I should be able to detect when the current cursor location or selection is a link already. At the moment this causes nested anchor tags instead of updating the existing link.

The FCKEditor JavaScript API is not too helpful: "Working with the selection in the editor: Use the Selection Object"

I would be happy with examples related to this or documentation about selection object. Thank you!

A: 

The way of setting URL for an existing link is something like this:

var selection = fckInstance.Selection;

if (selection.HasAncestorNode('A')) {
    var link = selection.MoveToAncestorNode( 'A' ) ;

    link.href = newURL;
    link.setAttribute('_fcksavedurl', newURL);
    link.innerHTML = newTitle;
} else {
    // create new link
}
Petteri Hietavirta