Thanks for a fantastic editor! I am porting a plug-in from the FCKEditor and am running into a simple problem that I can't seem to get around.
This may be a stupid question, but how do I get the currently selected text out of the ckeditor?
I have seen the below code used in some examples, but it does not work for me in IE (it works fine in Firefox). In IE, selectedText ends up being '[object Object]'.
var selected text = "";
if (oEditor.getSelection().getType() == CKEDITOR.SELECTION_TEXT) {
selectedText = "" + top.oEditor.getSelection().getNative();
}
I tried the below code instead, but the getNative() object returned does not seem to be a standard IE selection object; the createRange() call throws an exception.
var selected text = "";
if (oEditor.getSelection().getType() == CKEDITOR.SELECTION_TEXT) {
if (CKEDITOR.env.ie) {
selectedText = "" + top.oEditor.getSelection().getNative().createRange().text;
} else {
selectedText = "" + top.oEditor.getSelection().getNative();
}
}
There must be an easy way to get the selected text out; can someone clue me in?
This may be a stupid question, but how do I get the currently selected text out of the ckeditor?
I have seen the below code used in some examples, but it does not work for me in IE (it works fine in Firefox). In IE, selectedText ends up being '[object Object]'.
var selected text = "";
if (oEditor.getSelection().getType() == CKEDITOR.SELECTION_TEXT) {
selectedText = "" + top.oEditor.getSelection().getNative();
}
I tried the below code instead, but the getNative() object returned does not seem to be a standard IE selection object; the createRange() call throws an exception.
var selected text = "";
if (oEditor.getSelection().getType() == CKEDITOR.SELECTION_TEXT) {
if (CKEDITOR.env.ie) {
selectedText = "" + top.oEditor.getSelection().getNative().createRange().text;
} else {
selectedText = "" + top.oEditor.getSelection().getNative();
}
}
There must be an easy way to get the selected text out; can someone clue me in?
The answer is in this other
The answer is in this other post: http://ckeditor.com/forums/CKEditor-3.x/getSelection-getNative-returns-object-Object. The code is:
Oh, and note, the code you
Oh, and note, the code you have works for IE8 and less, my code works for IE9 or greater...