How can one define / manipulate the selection of textarea in Safari from JavaScript?
I have JavaScript code that does two things:
- extracts the selected text from the text area
- adds a prefix and suffix to the selected text
Currently, the code uses the properties of the selectionStart
and the selectionEnd
textbox to figure out where the selection starts / ends, extracts the selection text and processes it, and then re-writes the textbox value with the prefix and suffix inserted in the correct places.
This implementation works fine in Firefox , but it doesn't work in Safari . Apparently, properties selectionStart
and selectionEnd
do not exist in WebKit. (I suspect the code also doesn't work in Google Chrome, which is also WebKit-based, although I haven't tested that.)
How can I accomplish these two operations in Safari?
a source to share
I believe you are looking for https://developer.mozilla.org/En/DOM:Selection
also works in Safari (not tested by me) (see http://lists.apple.com/archives/Web-dev/2005/Nov/msg00114.html
a source to share