View Single Post
Join Date: Jun 2006
Posts: 7,627
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Find location of highlighted text

 
0
  #3
Aug 8th, 2007
Here you go MS Boy... :-)
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script>
  4. function boundDim(oObject)
  5. {
  6. var oTextRange = document.selection.createRange();
  7. if (oTextRange != null) {
  8. alert("The bounding left is \n" + oTextRange.boundingLeft);
  9. oTextRange.pasteHTML("<b>" + oTextRange.htmlText + "</b>");
  10. }
  11.  
  12. }
  13. </script>
  14. </head>
  15. <body onclick="boundDim(this);">Hello to all. Hello to me.</body>
  16. </html>
The above is just a small example on what you can do with the API. Once the text is selected, you get its offset in pixels which you can then use to distinguish between the first and second foobar.
If my snippet doesn't give you what you need, also read on selection and range.

Do let me know if it works.
I don't accept change; I don't deserve to live.
Reply With Quote