I'm trying to use the document.getSelection to select text I have entered in an text area for a WYSIWYG editor. It only works if you select text outside the text area though. I don't know if there is a way you can make it select text inside the text area?
Below is the text area for a WYSIWYG text editor:
<iframe id="editor" width="100%" height="400px" contentEditable="true"></iframe>
You need to get the iframe document's selection:
var ifrDoc = document.getElementById("editor").contentWindow.document,
sel = ifrDoc.getSelection();
Note that for Internet Explorer you need document.selection.createRange() instead of document.getSelection().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With