Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

How do I surround selected text with arbitrary HTML in FCKEditor?

Hello,
I'm using FCKEditor in a web application.  I'm creating custom plugins which allow users to select from a list of drop downs and apply standard formatting to the selected text.
I can easily apply divs and such using ApplyStyle, what I haven't been able to figure out is how I surround the selected text with something like the following.
<DIV class=ooc><FIELDSET><LEGEND>OOC</LEGEND>
Selected Text would be here
</FIELDSET></DIV>
I can do the fieldset and the div by using ApplyStyle multiple times, what I haven't figured out is how to add the Legend.
0
dguillen
Asked:
dguillen
1 Solution
 
dguillenAuthor Commented:
I found an answer in an obscure post.

// get HTML from selection
function getSelectionHTML(selection) {
    var range = (document.all ? selection.createRange() : selection.getRangeAt(selection.rangeCount - 1).cloneRange());

    if (document.all) {
        return range.htmlText;
    }
    else {
        var clonedSelection = range.cloneContents();
        var div = document.createElement('div');
        div.appendChild(clonedSelection);
        return div.innerHTML;
    }
}

its used by doing the following

            var selection = "";

            if (FCK.EditorDocument.selection != null) {
                selection = getSelectionHTML(FCK.EditorDocument.selection);
            } else {
                selection = getSelectionHTMLFCK(EditorWindow.getSelection()); // after this, won't be a string
                selection = "" + selection; // now a string again
            }
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now