safari: get the word under the mouse pointer
i'm trying to find a clicked word in an onclick event handler.
somediv.onclick = function(event) {
var w = getClickedWord(event);
alert(w开发者_如何学Go)
}
getClickedWord()
uses range.moveToPoint
for msie and event.rangeParent/offset
for gecko, but Webkit seems to support neither. Any pointers?
Maybe you can try window.getSelection() , notice that this function returns a Selection object, so you should use it like following:
var sel = window.getSelection();
精彩评论