Hi,
I have been trying to modify slightly an old online wysiwyg that is based on an iframe.
I am in need of surrounding a selection with my own bits of code (div, span). I have found here on SitePoint some code that is allegedly doing exactly what I need, but still I cannot make it work. What have I been doing wrong? Just to explain, I know very little JavaScript, and I spent couple of hours tonite trying to write a correct syntax for the variables (sigh)
function catchSelection()
{
var s_selected = window.getSelection();
var o_element = document.getElementById("idContent");
o_element.innerHTML = o_element.innerHTML.replace(s_selected, "<span style='background:#FF0000'>" + s_selected + "</span>");
o_element.focus();
}
Looking at the source codes of hundreds of wysiwygs today I noticed that there’s something like pasteHTML, but I couldn’t make that work, either. Also tried to use getIFrameDocument instead of getElementById but to no avail, error is printed idContent is not defined all the time.
Can anybody help me here?
Thanks in advance!
Regards,
Greg