Discussion:
Position of a text into html page
Marina Dorelli
2010-03-25 14:44:33 UTC
Permalink
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?

Thanks in advance.
Neil Deakin
2010-03-25 15:15:10 UTC
Permalink
Post by Marina Dorelli
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.

Continue reading on narkive:
Loading...