The following code errors in IE 8 (I have not tested in other versions of IE), and it seems to work fine in Firefox. I am using CKEditor 3.4.2
The problem arises when I set the value of the to '' (empty string)
It does not matter how I set it
//Does not matter what one is used, both cause error editor.setData(''); $('#roomId .MessageImput').val('');
I am capturing the Enter key and then clearing the editor after Enter has been pressed.
The error message is: 'getSelection()' is null or not an object
it happens in ckeditor.js Line 51 Column 2160
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script src="Scripts/jquery-1.4.4.js" type="text/javascript"></script> <script src="Scripts/CKEditor/ckeditor.js" type="text/javascript"></script> <script src="Scripts/CKEditor/adapters/jquery.js" type="text/javascript"></script> </head> <body> <script type="text/javascript"> $(document).ready(function () { $('#roomId .MessageImput').ckeditor(); var editor = $('#roomId .MessageImput').ckeditorGet(); editor.on('key', function (event) { if (event.data.keyCode == 13) { processMessage(); } }); }); function processMessage() { $('#roomId .RoomBody').append($('<div></div>').html($('#roomId .MessageImput').val())); var editor = $('#roomId .MessageImput').ckeditorGet(); //Does not matter what one is used, both cause error editor.setData(''); $('#roomId .MessageImput').val(''); editor.focus(); } </script> <div id="ChatRooms"> <fieldset id="roomId"> <legend>Room Name</legend> <div class="RoomBody"> </div> <textarea class="MessageImput"></textarea> <button class="SubmitMessageButton"> Submit </button> </fieldset> </div> </body> </html>
Any help?
Re: Error in IE when setting data
The event needs to be canceled to prevent it from trying to process the enter key with:
The updated code looks like: