簡體   English   中英

在CKEditor插件中保存之前立即更新編輯器內容

[英]Update editor content immediately before save in CKEditor plug-in

我正在為CKEditor開發一個插件,需要在保存之前立即對編輯器的內容進行一些更改。 在FCKeditor中,我使用OnAfterLinkedFieldUpdate事件實現了這一點,但我還沒有找到在CKEditor中執行此操作的等效方法。 我原本希望有一個合適的事件可以掛鈎,但似乎沒有。 有誰知道這樣做的方法?

您可以使用getData事件,但要小心,因為它也被內部使用。

我已經提交了http://dev.fckeditor.net/ticket/5254來重新創建上一個活動

由於上面的鏈接實際上沒有關於替代OnAfterLinkedFieldUpdate事件的解決方案,我已經寫了一篇關於如何解決它的簡短帖子。

這是表格:

<form id="my_form" action="submit.php" method="post" name="my_form">
   <textarea id="my_text" name="my_text"></textarea>
   <input id="submitForm" type="submit" name="submitForm" value="Submit" />
</form>

JavaScript的:

var formSubmitted = false;
$("#submitForm").live('click', function(event) {
    if (formSubmitted === true) {
        formSubmitted = false;
        return;
    }
    event.preventDefault();
    //put here function to edit content == OnAfterLinkedFieldUpdate
    var editor = CKEDITOR.instances.my_text;
    var html = editor.getData();
    html.replace(searchvalue, newvalue);
    editor.setData(html);
    formSubmitted = true;
    $(this).trigger('click');
});

代碼在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM