function getSelect() {
if (document.getSelection) methodeselection = oEditor.FCK.EditorDocument.getSelection();
else if (document.selection) methodeselection = oEditor.FCK.EditorDocument.selection.createRange().text;
else return;
return methodeselection;
}
Mon, 03/03/2008 - 09:48
#1

Re: [New plugin] how to get HTML selected text ?
I'm a begginer, i don't know if it's the answer, it works for me ...
Re: [New plugin] how to get HTML selected text ?
Re: [New plugin] how to get HTML selected text ?
Re: [New plugin] how to get HTML selected text ?
Re: [New plugin] how to get HTML selected text ?
I noticed that is not working anymore in FCKeditor 2.6RC (and also in the 2.6 beta).
In IE you have to use this function to retreive the selected text.
In the current stable release 2.5.1 the function is working like a sharm!
Firefox users can use: and that is still working in 2.6RC!
I hope it will be fixed in the upcoming release of this great editor!
Re: [New plugin] how to get HTML selected text ?
According to the comment on ticket #2071:
So the code to will work now!
Re: [New plugin] how to get HTML selected text ?
var selection = ""; if(oEditor.EditorDocument.selection != null) { selection = oEditor.EditorDocument.selection.createRange().text; } else { selection = oEditor.EditorWindow.getSelection(); }Re: [New plugin] how to get HTML selected text ?
var selection = ""; if(oEditor.FCK.EditorDocument.selection != null) { selection = oEditor.FCK.EditorDocument.selection.createRange().text; } else { selection = oEditor.FCK.EditorWindow.getSelection(); }But it works great now. Excellent!
Re: [New plugin] how to get HTML selected text ?
var selection = ""; if(oEditor.FCK.EditorDocument.selection != null) { selection = oEditor.FCK.EditorDocument.selection.createRange().text; } else { selection = oEditor.FCK.EditorWindow.getSelection(); // after this, won't be a string selection = "" + selection; // now a string again }Re: [New plugin] how to get HTML selected text ?
There is some sample code for creating a non-dialog plugin over a Source Forge. It works - but only in IE. The problem in Safari and FireFox is the line containing the .createRange() method. The JS console says the method doesn't exist. This is the code. Is there an easy way to generalize this so it works in Safari and FireFox as well?
var FCKEmphasis = function(name) { this.Name = name; } FCKEmphasis.prototype.Execute = function() { if(document.all) { mySelection = FCK.EditorDocument.selection } else { mySelection = FCK.EditorWindow.getSelection() } myTextRange= mySelection.createRange() myText = myTextRange.text FCK.InsertHtml("<b>"+myText+"!</b>") myTextRange.select() }Thanks!
doug
Re: [New plugin] how to get HTML selected text ?
I haven't dug into this much, but you'll see from my previous post that createRange() is in an if statement. I'm pretty sure you need to do the same. That part of the code is called in IE, but you need an else for Firefox/Safari that contains other code.
Good luck.
Re: [New plugin] how to get HTML selected text ?
It turns out if you just make sure that the "range" related statements just get used in IE and make sure they aren't executed in Firefox/Safari (no substitutions with other methods) it seems to work just fine.
doug
Re: [New plugin] how to get HTML selected text ?
Thanks a lot, but this doesn't work in IE7 either. I always get an empty string in IE7.
Re: [New plugin] how to get HTML selected text ?
FCKEditor 2.6.4
Re: [New plugin] how to get HTML selected text ?
Try this to get the content of the selection on IE 7:
var selection = oEditor.FCK.Selection.GetSelection().createRange().text;