I have some JavaScript code that does two things:
- retrieves the selected text from a text area
- adds a prefix and suffix to that selected text
The code currently uses the selectionStart
and selectionEnd
properties of the textarea to figure out where the selection starts/end, extracts the selection text and processes it, and then re-writes the value of the textarea with the prefix and suffix inserted in the right spots.
This implementation works fine in Firefox but it does not work in Safari. Apparently the selectionStart
and selectionEnd
properties do not exist in WebKit. (I suspect that the code also does not work in Google Chrome, which is also WebKit-based, though I have not tested this.)
How can I perform these two operations in Safari?