I'm really struggling with the problem: in Internet Explorer, I want to insert plain text at the current position of the caret. This works fine for simple TEXTAREA elements, but it doesn't fully work for editable IFRAMEs, which is what I have.
In the script I use I create a TextRange object from the IFRAME document, which I use to insert text in the HTML at the cursor position.
<iframe id="editable"> <html> <body> Some really boring text. </body> </html> </iframe> <script type="text/javascript"> window.onload = function() { var iframe = document.getElementById('editable'); var doc = iframe.contentDocument || iframe.contentWindow.document; doc.body.innerHTML = iframe.textContent || iframe.innerHTML; </script> <input type="button" value="Insert" onClick="insert('foo');"/>
When I select the text in IFRAME, the selection will be replaced by "foo" - this is the expected behavior. But when I just put the caret somewhere in the text, the insert will not work.
Is this the usual behavior since there is no โreal choiceโ for the case when I just put the cursor somewhere or is it a bug with editable IFRAMEs in IE, since it works fine with simple TEXTAREA elements?
Is there a workaround?
source share