I wrote it to look for text because that's what you said you were having trouble targeting.

Normally, you can just compute the offsets of a node recursively to find it's position (most cases), but text nodes (nodeType == 3) are computed at page-reflow time and do not contain positioning attributes.

All I did was to find the text you were looking for, split it apart from the surrounding text and then wrap it in a <span> tag... which has positioning attributes and so can be tracked as per any other node.

No single method of searching/targeting the page content will work for everything, so you need to understand the types of content you will be serving and then adapt your "pointer" targeting correspondingly.

Basically, my goal was to help you understand the nature of the problem, and a reasonable approach to its solution... but you will definitely need to work on it yourself (possibly do some reading about javascript and DOM) before anyone can help you more.

I can help you with your version of the code if you like... but this thread is a little long and off-topic, so perhaps the CB and your public scratchpad might be better venues ?

-David


In reply to Re^10: Position on Web Page by erroneousBollock
in thread Position on Web Page by user2000

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.