CKEditor 'save' is different than submit

我与影子孤独终老i 提交于 2019-12-25 04:13:18

问题


I use this, to submit the form if you hit ctrl+enter:

$(function() {
    CKEDITOR.on('instanceReady', function(evt) {
        evt.editor.setKeystroke(CKEDITOR.CTRL + 13, 'save');
    })
})

Unfortunately this seems to be a bit different to pressing the submit button.

If I hit ctrl+enter I get a popup with a warning that there is changed data in the form, and that this data would get lost. If I choose "leave the page", then everything works fine (not data gets lost).

How can I make ctrl+enter work like pressing the submit button?


回答1:


It appears that the onbeforeunload event is triggered when you save the form.

Try this to override the save event and remove the event handler:

for (var i in CKEDITOR.instances) {
    CKEDITOR.instances[i].on('save', function(evt) {
        window.onbeforeunload = null;

        // if the above line doesn't work,
        // replace it with the next line removing the two slashes
        // $(window).off('beforeunload');
    });
}



回答2:


Did you try replacing "save" with "submit".

CKEditor has a cache which saves the things you've typed so when you loose connection, etc. your content won't be gone.



来源:https://stackoverflow.com/questions/40740695/ckeditor-save-is-different-than-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!