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??
asked Apr 18, 2012 at 9:58
Betamoo
16.2k25 gold badges78 silver badges110 bronze badges
-
Due to send again information to server, i can suggest you tu use some Ajax?DonCallisto– DonCallisto2012年04月18日 10:01:19 +00:00Commented Apr 18, 2012 at 10:01
-
sure.. but still need to identify the offset of the selected text...Betamoo– Betamoo2012年04月18日 10:02:28 +00:00Commented 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.DonCallisto– DonCallisto2012年04月18日 10:03:41 +00:00Commented Apr 18, 2012 at 10:03
1 Answer 1
You need to do that using selection rage.
For example using getSelection() method.
answered Apr 18, 2012 at 10:00
antyrat
27.7k9 gold badges78 silver badges77 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default