Hi!
I am trying to implement CKeditor to my project. As i have it in the past a lot of times that i accidentally navigated away from the editor window, i want to have a alert message before that happens.
I managed it to create a alert message with this code ...
This code cases Firefox to show a alert message before i leave the page. But this ONLY if the content in the editor has changed. That works great so far. But the alert box shows as well when the Save button is pressed.
I would like to show the message only when
1.) The content has changed AND
2.) The user did not press the "save" button.
Thanks, Bye
Gerhard
I am trying to implement CKeditor to my project. As i have it in the past a lot of times that i accidentally navigated away from the editor window, i want to have a alert message before that happens.
I managed it to create a alert message with this code ...
ckeditor = CKEDITOR.instances.note_editor; ckeditor.execCommand('maximize'); window.onbeforeunload = function() { return before_leave_page(); }; window.onunload = function() { return before_leave_page(); }; function before_leave_page () { if (ckeditor.checkDirty() === true) { return 'You have unsaved changes in this note. Click Cancel now, then "Save" to save them. Click OK now to discard them.'; } };
This code cases Firefox to show a alert message before i leave the page. But this ONLY if the content in the editor has changed. That works great so far. But the alert box shows as well when the Save button is pressed.
I would like to show the message only when
1.) The content has changed AND
2.) The user did not press the "save" button.
Thanks, Bye
Gerhard
Re: Show notification before user leaves the page
Re: Show notification before user leaves the page
Anybody who can help me with this???
The development team rejected any support so far and i did not find anything in the documentation about it. Any help would be great!!!
Re: Show notification before user leaves the page
Probably this topic will help you: http://cksource.com/forums/viewtopic.php?f=11&t=16066
It seems to me that the only way in your case is to create your own plugin.
Re: Show notification before user leaves the page
Thanks for that link.
I hope that i understand everithing as i am not very expirienced with javascript. I am more a PHP geek.
When i create such a plugin. Do i have to re-write the complete submit and save stuff? Because i thought i could simply set a global variable and trigger on it so i can hide the alert box.
Thanks for your help.
Re: Show notification before user leaves the page
You're thinking in the right direction
At least, I would do the same: set the global flag and make it active when the alert box is not needed.
Re: Show notification before user leaves the page
I had a talk to a lot of people because my js knowledge is not so well.
And one of them (http://www.kriesi.at) showed me a way to implement it without any plugin stuff. Might be that this is not the nices and cleanest way, but it works without any problems.
If i have understood the explanation correctly, the small js code will copy the onclick="" event content from the editor. The it assigns a new function to the onclick="" event where a global variable is set and then the original code from the onclick="" event is executed.
Here is the code ...
It uses the the class name to address the save button element.
A possible solution
I came across this thread searching on Google. A bit late, but maybe others are searching the same.
If found this code helpful. There is only a typo, ")" missing at the end:
I haven't tested the "robuster implementation".