Re: Position of a text into html page

Neil Deakin <[email protected]> Thu, 25 Mar 2010 11:15:10 -0400
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
Marina Dorelli wrote:
> Hi all,
> I would like to know if it is possible to get the position of a selected
> text into the html page through any DOM API.
> Do I have to use Xpointer lib, instead?

You can use getSelection() to get the selection. It contains a number of 
DOM Range objects. In Firefox 3.6, you can use getClientRects() or 
getBoundingClientRect() on those range objects to get the rectangles of 
each part of the selection. The former returns a list of each rectangle 
for each line or piece of the selection, whereas the latter returns the 
total bounding box.