开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜