Ticket #5950 (closed Bug: invalid)
getSelection IE7 & IE6 = is null or not an object
| Reported by: | thinkap | Owned by: | |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | General | Version: | 3.3.1 |
| Keywords: | Cc: |
Description
When i try to extract the selected text from the editor i receive the error "getSelection is null or not an object" only happens in ie6 & ie7. it works great in ie8, firefox, chrome & safari.
var editor_name = 'email_ckeditor';
var mySelection = CKEDITOR.instances[editor_name].getSelection();
if (CKEDITOR.env.ie) {
mySelection.unlock(true);
selectedText = mySelection.getNative().createRange().text;
} else {
selectedText = mySelection.getNative();
}
alert( selectedText );
also tried without luck
var editor_name = 'email_ckeditor';
if (CKEDITOR.env.ie) {
selection = CKEDITOR.instances[editor_name].getSelection().document.$.selection.createRange().text;
} else {
selection = CKEDITOR.instances[editor_name].getSelection().getNative();
};
alert( selection );
Change History
Note: See
TracTickets for help on using
tickets.

The problem with IE is that it doesn't preserve the selection on different frames. So, in the exact moment you click the link, the selection is lost in the editor.
The solution for it, fortunately, is quite simple. It's enough to add unselectable="on" to you <a> element, so it'll not grab the selection when clicking on it.