Using jQuery to grab the content from CKEditor's iframe

前端 未结 11 1578
既然无缘
既然无缘 2020-11-29 01:20

I have a custom-written CMS that uses CKEditor *(FCKEditor v3) for editing content. I\'m also using the jQuery Validation plugin to check a

相关标签:
11条回答
  • 2020-11-29 02:01

    I solved this problem with the current version: http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js

    After line 55 this.submit( function( event ) { - i added this code:

    if (typeof CKEDITOR !== "undefined") {
        for ( instance in CKEDITOR.instances )
            CKEDITOR.instances[instance].updateElement();
    }
    
    0 讨论(0)
  • 2020-11-29 02:02

    I took a slightly different approach I figured it would be better to use ckeditor's update function and since keyup was being used the timeout wasn't needed

    CKEDITOR.instances["editor1"].on("instanceReady", function()
    {
    //set keyup event
    this.document.on("keyup", CK_jQ);
    
     //and paste event
    this.document.on("paste", CK_jQ);
    }
    
    function CK_jQ()
    {
       CKEDITOR.instances.editor1.updateElement(); 
    }
    
    0 讨论(0)
  • 2020-11-29 02:08

    The contentDom event worked for me and not the instanceReady... I would really like to know what the events ae, but I assume they are proprietary...

    var editor = CKEDITOR.replace('editor');
    
    CKEDITOR.instances.editor.on("instanceReady", function(){
        this.on('contentDom', function() {
            this.document.on('keydown', function(event) {
                CKEDITOR.tools.setTimeout( function(){ 
                    $(".seldiv").html(CKEDITOR.instances.editor.getData()); 
                }, 1);
            });
        });
        this.on('contentDom', function() {
            this.document.on('paste', function(event) {
                CKEDITOR.tools.setTimeout( function(){ 
                    $(".seldiv").html(CKEDITOR.instances.editor.getData()); 
                }, 1);
            });
        });
        edits_clix();
        var td = setTimeout("ebuttons()", 1);
    })
    
    0 讨论(0)
  • 2020-11-29 02:09

    Wouldn't it be better to do just this:

    CKEDITOR.instances.editor1.on('contentDom', function() {
              CKEDITOR.instances.editor1.document.on('keyup', function(event) {/*your instructions*/});
            });
    

    ref: http://cksource.com/forums/viewtopic.php?f=11&t=18286

    0 讨论(0)
  • 2020-11-29 02:12

    Another generic solutions to this would be to run the following whenever you try to submit the form

    for ( instance in CKEDITOR.instances )
                CKEDITOR.instances[instance].updateElement();
    

    This will force all CKEDITOR instances in the form to update their respective fields

    0 讨论(0)
  • 2020-11-29 02:13

    I had success with this:

    console.log(CKEDITOR.instances.editor1.getData());
    
    0 讨论(0)
提交回复
热议问题