Olemis Lang
Olemis Lang

Reputation: 768

How to scroll CKEditor while in WYSIWYG mode?

I'm building a site and some pages include instances of CKEditor (i.e. the WYSIWYG editor) . They are working fine so far. Nonetheless the fact is that sometimes I need to scroll edit area right to the bottom without requiring user interaction (i.e. perform scrolling programmatically from within the body of an external event handler) .

Q:

PS: I couldn't find anything in the docs, and Googling didn't help at all :( .

Upvotes: 3

Views: 2149

Answers (2)

Joel Peltonen
Joel Peltonen

Reputation: 13432

I know this is an old Q, but it showed up as related on a newer one I recently answered. To copy from there for future reference: I you have access to jQuery, this might do the trick.

var editor = CKEDITOR.instances.editor1; 
var jqDocument = $(editor.document.$);
var documentHeight = jqDocument.height();
jqDocument.scrollTop(documentHeight);

This method is very similar to the earlier answer. This assumes CKE > 4.x, because it uses CKEDITOR.instances dot notation, but you can use this with oldr versions using this notation: CKEDITOR.instances["editor1"]. Here you use the CKE instance and grab the referring document from there. Should be doable non-jquery as well, but can't be bothered right now. If you want native JS, add a comment :)

Upvotes: 0

Román
Román

Reputation: 1953

Olemis

I don't know of an official way, but managed to hijack - shame on me- the CKEditor at http://ckeditor.com/demo and the following code worked for IE/FF (you gotta try other browsers I'm afraid)

document.getElementById("ifr").contentWindow.scrollTo(0,3)

where "ifr" is a name I gave at runtime to the iframe. Great news that both browsers support great developer tools and a js console that works wonders...

Now, the CKEditor frame doesn't have a proper id, but the element it is contained in does (in that demo it is a TD id'ed "cke_contents"). Mileage may vary. That suggests you can spicy it up with jquery.

Let me know if that 'hack' properly works, otherwise let's hope someone comes with some workable code.

Regards

Upvotes: 2

Related Questions