开发者

safari: get the word under the mouse pointer

开发者 https://www.devze.com 2022-12-08 06:35 出处:网络
i\'m trying to find a clicked word in an onclick event handler. somediv.onclick = function(event) { var w= getClickedWord(event);

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

精彩评论

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