Possible Duplicate:
Insert text before and after the selected text in javascript
I want to put some specified text (where possible in iframe when designmode on) before and after any selected text in an HTML document. document.getSelection()
or document.selection.createRange().text
returns only the text itself not the position.
Is there anyway to replace the selected text?
Anyway to insert specific text before and after selcted text anywhere in the document?
I answered a related question of yours earlier today:
https://stackoverflow.com/a/8740153/96100
Also, here's an answer I posted to a remarkably similar question a year ago, recently updated to work in IE 9:
https://stackoverflow.com/a/4770592/96100
Finally, here's a version of the function from the second linked answer for your editable iframe. It allows you specify a document object: