Hello, I am trying to write a JavaScript to find the word user moused over.
FireFox supports event.rangeOffset, which is the *character* offset the cursor is at within the element. Given English word, using this offset, I can find the previous and next spaces and know the word under the cursor. But seems that Webkit does not support event.rangeOffset. Then, how to find a word user moused over? or how to convert the event.clientX to the *character* offset within an element? My understanding is that it must involve encoding/font/font size, but I do not have clear idea on how it works. Appreciate any input! Thanks, Xiaomei P.S. Following example (event.rangeOffest) works in FireFox, but not Safari/Chromium. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> <script type="text/javascript"> function showToolTip(ev) { if (ev.rangeOffset) { //alert("yes again" + ev.rangeOffset); document.getElementById('divCoord').title = ev.rangeOffset; } } </script></head> <body> <div id="divCoord" onmouseover="showToolTip(event)">hello, how are you. </div><!-- <div id="divCoord" onmouseover="showToolTip(event)">广告计划</div> --> </body></html>
_______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev