views:

21

answers:

0

Hi,

i tried different methods to insert a text into an iframe. My iframe runs in "designMode='on'". Which makes it possible to be editable. I use the jquery.fieldselection plugin to get the current selection which i had to fix to be able to read from iframes.

The problem is now i want to add a simple plain text in the ifram at the current cursor position.

This one works, but the written text replace ALL text in the iframe with the "HelloWorld".

var doc = $( '#iframe_content').contentDocument();
doc.open();
doc.write( "HelloWorld");
doc.close();

iframe_content is the id of the iframe. Then i tried using the createRange function. But this doesnt work at all.

When i fetch the iframe with $('#iframe_content') and try to access the contentDocument or contentWindow attribute, then it throws an error telling me both are not defined.

Iam able to use the "execCommand" function replacing some text. When using the "insertHTML" parameter with execCommand it returns a false putting it in the iframe. I guess it expects real HTML Code.

My task is pretty simple, wherever the cursor in the iframe currently is, i want to add a text at that position.

Does anybody have any experience with that? Searched stackoverlow but found only solutions to add text in a textarea, which doesnt work for iframe.

My code should be compatible with FF, IE is not needed.

Would appreciate any help. Wasted hours testing and coding this. :-(