I have found a very useful function for textarea
function getSelectionRange(oElm) { var r = { text: '', start: 0, end: 0, length: 0 }; // W3C/Gecko if (oElm.setSelectionRange) { r.start= oElm.selectionStart; r.end = oElm.selectionEnd; r.text = (r.start != r.end) ? oElm.value.substring(r.start, r.end): ''; } // IE else if (document.selection) { if (oElm.tagName && oElm.tagName === 'TEXTAREA') { var oS = document.selection.createRange().duplicate(); var oR = oElm.createTextRange(); var sB = oS.getBookmark(); oR.moveToBookmark(sB); } else var oR = document.selection.createRange().duplicate(); r.text = oR.text; for (; oR.moveStart('character', -1) !== 0; r.start++); r.end = r.text.length + r.start; } r.length = r.text.length; return r; }
Its working fine with a standard textarea
$('#button').click(function() { var obj = document.getElementById('editor1'); console.log(getSelectionRange(obj)); });
now I use editor = CKEDITOR.replace('editor1',.....
$('#button').click(function() { var obj = editor; //var obj = CKEDITOR.instances['editor1']; console.log(getSelectionRange(obj)); });
But now I get only Object { start=0, end=0, length=0, text=""}
What is my mistake? Can anybody help me?
Re: getSelectionRange() in CKEditor
nobody has any idea?
Re: getSelectionRange() in CKEditor
Not sure if this is similar to my issue (viewtopic.php?f=11&t=22237&p=56296#p56296)
Have you tried calling focus on the editor object?