SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2010
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get the selected content even if it is an image

    Hello,

    I am trying to retrieve the html markup of the content selected by the user in the CKEditor 3.6.5.

    It works fine when the content is some text.

    But it does not retrieve it if the content is an image.

    This is needed to then wrap a link around the image.

    Here is the code that works for the text content:

    var getSelectedText = function(editor) {
    var selectedText = '';
    var selection = editor.getSelection();
    console.log("The selected element: " + selection.getSelectedElement());
    if (selection.getType() == CKEDITOR.SELECTION_TEXT) {
    if (CKEDITOR.env.ie) {
    selection.unlock(true);
    selectedText = selection.getNative().createRange().text;
    } else {
    selectedText = selection.getNative();
    console.log("Ths is not IE");
    }
    console.log("The type is CKEDITOR.SELECTION_TEXT");
    }
    console.log("The selected text: " + selectedText);
    return(selectedText);
    }

    I'm trying to see how to have it also retrieve image content.

    To log in:
    http://demo.learnintouch.com/engine/...&password=demo

    To see it in action:
    http://demo.learnintouch.com/engine/...hp?dynpageId=2

    Kind Regards,

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2010
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I solved the issue, at least on Chrome and Firefox, with the function:

    var getSelectedContent = function(editor) {
    var content = editor.getSelection().getStartElement().getOuterHtml();
    return(content);
    }

    It does get the selected image.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •