开发者

how to use javascript to get the position of highlighted words in a html

How can I use Javascript to ge开发者_JAVA百科t the position of highlighted words in an HTML file?


Try looking into window.getSelection: https://developer.mozilla.org/en/DOM/selection

This is for Firefox though.

You will need to do research to make it cross-browser.

Maybe there is a open-source library that does this.


You can use Rangy (http://code.google.com/p/rangy).

A cross-browser JavaScript range and selection library. It provides a simple standards-based API for performing common DOM Range and Selection tasks in all major browsers, abstracting away the wildly different implementations of this functionality between Internet Explorer and DOM-compliant browsers.

(Disclaimer: This answer is promoting the comment from the author that library to an answer, where it belongs)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜