CKEDITOR.instances.editor1.insertHtml('<a href=\x22www.google.com\x22>' + CKEDITOR.instances.editor1.getSelection().getNative() + '</a>');<a href="www.google.com">[object Object]</a>
http://blog.tommed.co.uk/2009/09/07/how ... -v3-plugin
CKEDITOR.instances.editor1.insertHtml('<a href=\x22www.google.com\x22>' + CKEDITOR.instances.editor1.getSelection().getNative() + '</a>');<a href="www.google.com">[object Object]</a>
Re: getSelection() - getNative() returns [object Object]
Re: getSelection() - getNative() returns [object Object]
Make a selection in the editor (object named 'editor') and refer to it.
This will display the text under the selection:
There are also a lot of other properties of '$'
Like start_element.$.href,
start_element.$.className
start_element.$.style.fontWeight
Or to retrieve an 'onclick' event in the current selection:
for (i=0; i<start_element.$.attributes.length;i++ ) { if (start_element.$.attributes[i].name.indexOf('onclick')>-1) { alert(start_element.$.attributes[i].value); } }I think there should be a better (more functional) way but it works!
There is a lot to be learned though...
Re: getSelection() - getNative() returns [object Object]
this will give you the selected text. but you will not get HTML tags.
Re: getSelection() - getNative() returns [object Object]
CKEDITOR.instances.instanceName.getSelection().getStartElement().getOuterHtml()
You'll get all the HTML that's selected. And it's cross-browser (unlike the actual javascript outerHTML method).
Re: getSelection() - getNative() returns [object Object]
/** * Retrieve HTML presentation of the current selected range, require editor * to be focused first. */ CKEDITOR.editor.prototype.getSelectedHtml = function() { var selection = this.getSelection(); if( selection ) { var bookmarks = selection.createBookmarks(), range = selection.getRanges()[ 0 ], fragment = range.clone().cloneContents(); selection.selectBookmarks( bookmarks ); var retval = "", childList = fragment.getChildren(), childCount = childList.count(); for ( var i = 0; i < childCount; i++ ) { var child = childList.getItem( i ); retval += ( child.getOuterHtml? child.getOuterHtml() : child.getText() ); } return retval; } };Re: getSelection() - getNative() returns [object Object]
i really appreciate the prototype
CKEDITOR.editor.prototype.getSelectedHtml
but it does not work on IE7 and i guess also to old version.
I looked and the "getSelction" retrieve a NULL :-/
Any suggestion!
Re: getSelection() - getNative() returns [object Object]
g = CKEDITOR.instances.editor; // Your ckeditor if (CKEDITOR.env.ie) { selection = g.getSelection().document.$.selection.createRange().text; } else { selection = g.getSelection().getNative(); } alert ( selection );Hope it helps you,
Cheers
Re: getSelection() - getNative() returns [object Object]
Note that the editor document should hold focus to make this function work.
Re: getSelection() - getNative() returns [object Object]
maybe in IE6,you should user
CKEDITOR.instances.txtContent.getSelection().getNative().createRange().text;
in Ff,you should use
CKEDITOR.instances.txtContent.getSelection().getNative();