views:

27

answers:

1

Hi,

I want to build a FireFox addon that can capture a webpage as an image (which seems simple using a canvas object) and also preserve the XY postions of the hyperlinks present in the webpage.

I wanted to know if there are any DOM methods that can help me extract the geometry info (XY positions and the height and width) of all the hyperlinks in a webpage?

I am pretty much stuck here, hence any help or leads will be highly appreciated!

Thanks, Kapil

A: 

It seems that you can "walk" through the offsetParent objects and add all the offsetLeft attributes alltogether and then get a absolute value.

Eg. for the dom tag link on this page :

A -> offsetLeft = 110
A -> offsetParent(HTMLTableCellElement) -> offsetLeft = 60
A -> offsetParent -> offsetParent(HTMLTableElement) -> offsetLeft = 195
A -> offsetParent -> offsetParent -> offsetParent(HTMLBodyElement) -> offsetLeft = 0

110 + 60 + 195 + 0 = 365px.

Since the page is centered the 2nd last attribute will change depending on your browser size.

Oh, and ofcourse the other value would be offsetTop.

lithorus
Thanks a lot Lithorus! This helped a lot!
Kapil
That's the idea behind http://www.quirksmode.org/js/findpos.html (from some other SO answer). I have found that it gives the upper left corner of the *first* word in the link, which is generally okay, unless the link wraps to the next line. Then you might want the upper left corner of the "bounding box" that contains the link. Anyone know how to get that?
MatrixFrog