0

There is functionality to find the caret(^) symbol in Telerik editor, I have searched over internet , i found few links ,they recommended to replace getSelection() instead of selection

var range = editor.get_document().getSelection().createRange();

but unfortunatly it is not working.

Actual code

   var range = editor.get_document().selection.createRange();
            var oRange = range.duplicate();
            oRange.collapse(false);
            if (oRange.findText("^")) {
                oRange.select();
            }
            else {
                editor.set_html("");
                editor.set_html(currentHtml);
                oRange.findText("^")
                oRange.select();
            }

error :Unable to get property 'createRange' of undefined or null reference

Updated code :

  var range = editor.get_document().getSelection().createRange();
                var oRange = range.duplicate();
                oRange.collapse(false);
                if (oRange.findText("^")) {
                    oRange.select();
                }
                else {
                    editor.set_html("");
                    editor.set_html(currentHtml);
                    oRange.findText("^")
                    oRange.select();
                }

Error: Object doesn't support property or method 'createRange' how can fix it.

King_Fisher
  • 1,171
  • 8
  • 21
  • 51
  • Your code shows `.selection` instead of `.getSelection()`. The editor object has no `.selection` property. – trincot Oct 22 '16 at 08:55
  • I'm getting the same error when modified to .getSelection(). – King_Fisher Oct 22 '16 at 09:15
  • Please update your question with the exact code you are running. As it stands now, the error message and code do not correspond. – trincot Oct 22 '16 at 09:23
  • [createRange](https://developer.mozilla.org/en-US/docs/Web/API/Document/createRange) documentation suggests it's a property of `Document`, not `Selection` object. have you tried `editor.get_document().createRange()` ? or use [`addRange`](https://developer.mozilla.org/en-US/docs/Web/API/Selection/addRange) method on the selection? – Aprillion Oct 22 '16 at 10:17
  • when I changed that , it says Object doesn't support property or method 'duplicate' @Aprillion – King_Fisher Oct 22 '16 at 10:35
  • eeeh, [`cloneRange`](https://developer.mozilla.org/en-US/docs/Web/API/Range/cloneRange)? – Aprillion Oct 22 '16 at 10:47
  • @Aprillion now it says "Object doesn't support property or method 'findText' " but it was worked fine in IE 10. – King_Fisher Oct 22 '16 at 10:54
  • welcome to web development and the beloved IE browser... I'm afraid none of the standard [`Range` methods](https://developer.mozilla.org/en-US/docs/Web/API/Range) are similar to `findText`, I suggest you to describe the problem (business logic) you are trying to solve in plain english - something should happen if the user selects text that contains ^ in some editor??? – Aprillion Oct 22 '16 at 11:28
  • when user press F2 , have to select(highlight) the caret(^) symbol in Telerik Editor contents. – King_Fisher Oct 22 '16 at 11:41

0 Answers0