How to programmatically determine name of CKEditor instance

后端 未结 6 2002
野趣味
野趣味 2021-01-05 03:40

I\'ve added a CKEditor instance programmatically to my page in the code-behind of my ASP.NET page:

VB.NET:

itemEditor = New CkEditor
cell.Controls.Ad         


        
相关标签:
6条回答
  • 2021-01-05 04:04

    Well I've found a way... but I don't like it much...

    I've added a Hidden Field control to the page, after adding the editor, and put the editor's ClientId in its value:

    Dim hdn As New HiddenField
    With hdn
        .ID = "HiddenField"
        .Value = itemEditor.ClientID
    End With
    cell.Controls.Add(hdn)
    

    .. and then in the JavaScript, I can get the hidden field, and hence the editor name as follows:

    function GetCkText()
    {
        var hdn = document.getElementById("HiddenField");
        var editorName = hdn.getAttribute("value");
        var editor = CKEDITOR.instances[editorName];
        alert(editor.getData());
        return false;
    }
    

    But it's a bit inelegant, to say the least. Anyone got a better way?

    0 讨论(0)
  • 2021-01-05 04:06

    The following code:

    var allInstances=CKEDITOR.instances;
    for ( var i in allInstances ){
        alert(allInstances[i].name);
    }
    

    works fine for me.

    0 讨论(0)
  • 2021-01-05 04:10

    Assuming you only have one editor instance:

    for ( var i in CKEDITOR.instances ){
       var currentInstance = i;
       break;
    }
    var oEditor   = CKEDITOR.instances[currentInstance];
    

    Here is what the JavaScript API says about instances.

    Here is another way of defining the CKEditor. Here 'fck' is the input fields id:

    CKEDITOR.replace( 'fck', {
        customConfig : prefix + 'js/ckeditor/config.js',
        height: 600,
        width: 950
    });
    
    editor = CKEDITOR.instances.fck;
    

    Notice how I am then able to reference the instance using .fck.

    0 讨论(0)
  • 2021-01-05 04:15

    If you are using CKEDITOR.appendTo(...), keep in mind that the ckeditor does create an instance name internally. So you can query for that name immediately after creating it, then store it somewhere, and use it later.

    var lvo_editor = CKEDITOR.appendTo( "my_div" , null , lvs_html ) ; 
    my_global_var  = lvo_editor.name                                 ;
    

    by the way: The CKEDITOR.replace(...) method allows you to define an instance name (see answer above)

    0 讨论(0)
  • 2021-01-05 04:17

    If you need the instance from a plugin, at least in version 4+ you can do this.

    CKEDITOR.currentInstance
    

    Here I am wanting to know the name of the textarea I applied ckeditor on.

    CKEDITOR.currentInstance.name
    
    0 讨论(0)
  • 2021-01-05 04:21

    If you only have a single instance and you do not know the name of it.

    CKEDITOR.instances[Object.keys(CKEDITOR.instances)[0]].getData()
    
    0 讨论(0)
提交回复
热议问题