开发者

CKEditor .focus() in instanceReady event is not working

I am having problems in setting the focus in instanceReady event of CKEditor 3.4.1. I have already tried the following two ways but both of them are not always working.

CKEDITOR.on('instanceReady', fun开发者_如何学运维ction(e) { CKEDITOR.instances.editor1.focus(); });


CKEDITOR.replace('editor1',
{
    on :
    {
        instanceReady : function( ev )
        {
            ev.editor.focus();
        }
    }
} );


or maybe try this, this is much simpler:

use startupFocus : true

so your code should look like this:

CKEDITOR.replace('editor1',
{
    startupFocus : true,
...


here you go my friend

CKEDITOR.replace('editor1',
{
    on :
    {
        instanceReady : function( ev )
        {
            CKEDITOR.instances.editor1.focus();
        }
    }
} );

or

CKEDITOR.replace('editor1',
{
    on :
    {
        instanceReady : function( ev )
        {
            this.focus();
        }
    }
} );


CKEDITOR.instances['instance-name'].on('instanceReady', function (event) {
            CKEDITOR.instances['instance-name'].focus();
        });


a bit late but:

CKEDITOR.replace( 'YourEditor', 
{ 
 on:
   {
     instanceReady : function( evt )
     {
       //Set the focus to your editor
       CKEDITOR.instances.YourEditor.focus();
      }
    }
}

works fine for me. Found here


Best way to me,

  1. find the CKEditor instance, then
  2. trigger focus event

    The critical point is to focus instance in timeout

    for (var instance in CKEDITOR.instances) {
    $timeout(function() { CKEDITOR.instances[instance].focus(); }); }

Note: I found the instance with a for loop. You may find better way to find the instance


Neither of the above answers worked for me. Here is what I did for CHROME and it works just fine:

CKEDITOR.instances['instance-name'].container.focus();


Dirty way (Make sure you read the comment under my answer):

jQuery('.cke_wysiwyg_frame').contents().find('body').focus();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜