I'm trying to get the user's selection and then stick it within a div. I can do this with no problem, grabbing the selection and then using InsertHtml. The issue I run into is if they've applied formatting to the text they've selected as it is lost in the selection. Rather through FCK.EditorWindow.getSelection(); and FCK.EditorDocument.selection.createRange().text; I only get the text they typed without any of the HTML the editor uses for formatting.
Not sure what the best way to go about doing this is.
Thanks
Not sure what the best way to go about doing this is.
Thanks
RE: Get User's Selection Including HTML
Also needed to use FCK.ExecuteRedirectedNamedCommand('Copy', null); instead to get it to copy in the first place, seems this method passes the command to the correct implementation for each browser.
RE: Get User's Selection Including HTML
Perhaps you will post your final solution here, so other members can make use of it too.
RE: Get User's Selection Including HTML
RE: Get User's Selection Including HTML
The font size dropdown uses the internal browser commands to change the font size of the selection, instead the Styles combo does get the selection and wraps it in the selected tag.
I'm currently using this two functions to get the HTML, although getting the HTML this way doesn't guarantee that wrapping it in a new tag and inserting back again into the document will create a well nested document.
for IE:
//returns an HTML string representing the current selection.
FCKSelection.GetSelectedHTML = function()
{
var oRange = FCK.EditorDocument.selection.createRange() ;
//if an object like a table is deleted, the call to GetType before getting again a range returns Control
switch ( this.GetType() )
{
case 'Control' :
return oRange.item(0).outerHTML;
case 'None' :
return '' ;
default :
return oRange.htmlText ;
}
}
for Gecko:
//returns an HTML string representing the current selection.
FCKSelection.GetSelectedHTML = function()
{
var oSelection = FCK.EditorWindow.getSelection();
//Gecko doesn't provide a function to get the innerHTML of a selection,
//so we must clone the selection to a temporary element and check that innerHTML
var e = FCK.EditorDocument.createElement( 'DIV' ) ;
for ( var i = 0 ; i < oSelection.rangeCount ; i++ )
e.appendChild( oSelection.getRangeAt(i).cloneContents() ) ;
return e.innerHTML;
}
RE: Get User's Selection Including HTML
To put the selection in the clipboard use FCK.EditorDocument.execCommand('copy');
and to grab it from the clipboard try something like:
content = FCK.GetClipboardHTML();
Good luck!
RE: Get User's Selection Including HTML
content = FCK.GetClipboardHTML();
as when i use it, it gives me error that FCK is null or not a object
my code
var content = FCK.GetClipboardHTML();
var oEditor = FCKeditorAPI.GetInstance('FCKeditor1');
oEditor.FCK.InsertHtml( content || "" ) ;
thanks