hi i have ckeditor and one button for save ckeditor text whith ajax .
<textarea id="editor1" name="editor1"></textarea>
<input type="button" name="send" id="send" value="Send" onclick="save()">
i want remove button and when key press enter save text whith ajax ( run save function ) but when press enter in ckeditor line break . and how use enter exchange button?
<textarea id="editor1" name="editor1"></textarea>
if (enter press in any where web page ) do save();
This is code I created for a site a while back, it allows you to submit on enter, however will allow you to hold shift+enter to create a new line (as text areas that auto submit should).
It's written using jQuery.
However, I'm not certain it will work inside CK Editor. The best way to do this would be to add something like this to your config file:
which will add the
save
event on enter, but will keep the other default keystrokes.What you need to do is capture the
keyup
orkeydown
event with jQuery, and check thekeyCode
of theevent
to see if it was the enter key that was pressed.Eg:
Javascript keyCode reference: http://asquare.net/javascript/tests/KeyCode.html
Edit: oops, misread question - see updated answer. Changed selector to target body instead of the textarea, but as @KevinB said, probably a bad idea.
The important part is that the content in CKEditor is an iframe, so those solutions that try to check key presses on the current document will fail.
The solution is as simple as this using the CKEditor events and without relying on any external library:
You can test it here: http://jsfiddle.net/zjkSR/ (look at your console)