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 g开发者_StackOverflow中文版eometry 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
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.
精彩评论