1

How to identify what text the user has selected in the web page??

Example: I want to build an application similar to online translation:

  • The user is reading some html (provided to the user through my server)
  • Then he/she selects a sentence in that page (asking for its translation)
  • So the javascript should handle this event and send back to the server asking for the translation...

Any ideas how to know what text the user is currently selecting??

3
  • Due to send again information to server, i can suggest you tu use some Ajax? Commented Apr 18, 2012 at 10:01
  • sure.. but still need to identify the offset of the selected text... Commented Apr 18, 2012 at 10:02
  • Ok, just dind't understood the real essence of the question. So antyrat answer seems to be very nice. Commented Apr 18, 2012 at 10:03

1 Answer 1

4

You need to do that using selection rage.

For example using getSelection() method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.