I want the user to select some text (in a static block which could include tables, images etc) and submit a form. I want to be able to identify what was selected, and thus highlight that text when it is displayed again (using PHP). The idea is that they can add comments and link them to the specific phrase in the text.
With Gecko, I decided the easiest way was (on submit) to insert some marker text at either end of the selection (e.g. [START], or something a little more sophisticated), copy the HTML to a hidden field, and then read this field after it is posted. Gecko provides all the text offsets to do this.
Not IE. The closest I could come up with was
[CODE] range=document.selection.createRange();
range.pasteHTML(‘[START]’+range.htmlText+'[END]’)
which falls over if one end happens to be in a different node to the other (e.g. selecting text across two table cells).
What’s the best way to achieve this in IE?
Many thanks,
Tim