Cannot move ckeditor 4 selection to beginning
Posted
by
Gary Hillerson
on Stack Overflow
See other posts from Stack Overflow
or by Gary Hillerson
Published on 2013-10-31T03:51:12Z
Indexed on
2013/10/31
3:53 UTC
Read the original article
Hit count: 217
JavaScript
|ckeditor
I've been exploring numerous solutions in stackoverflow and elsewhere to try to get ckeditor 4 to scroll to the top after I've programmatically added a number of pages to it, using CKEditor's InsertHtml function. After adding my html, which looks fine, I want to position the cursor at the beginning.
Here's one of a variety of things I've tried without success:
function MoveCaretToStart(myEditor) {
var range = new CKEDITOR.dom.range( editor.document );
range.selectNodeContents(editor.document.getBody());
range.moveToElementEditStart(range.root); // also tried range.collapse(true);
range.select();
}
...
MoveCaretToStart(CKEDITOR.instances['myEditor']); // which already has contents in it
This doesn't throw any errors, but also doesn't move the cursor position (it remains at the end of the doc). I thought this one would be easy, but it sure hasn't been. Any help appreciated.
© Stack Overflow or respective owner