guettli guettli - 1 year ago 80
Javascript Question

CKEditor 'save' is different than submit

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?

Answer Source

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');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download