views:

118

answers:

2

I'm looking for a Javascript library to be able to measure the time a div (or any other object) has been in "focus" (as in: the browser is showing and the window is focused; not the normal Javascript focus event).

Do you know if something like that exists ? or something similar I can tweak?

Edit: Ok. Rephrased to avoid misunderstandings.

A: 

You cannot detect what a user is looking at with JavaScript.

You will need software that hooks into a webcam and includes face/expression recognition, which is not a trivial task, and I'm not sure if it is currently possible to actually detect what is being looked at using this method.
Have a look here: http://pages.cpsc.ucalgary.ca/~hanlen/vision/facelinks.html

You will then need to integrate this into a website, maybe using Flash, or a browser plugin.

Once you've got all that, you could actually use JavaScript to communicate with Flash to tell it where the components on the page are, using the jQuery offset function.

Peter Boughton
+1  A: 

I'm pretty sure I understood your question right away! . .

If you mean 'in focus' as in 'visible on the screen' you can figure this out via window extents and body.scrollTop and absolute position of divs computed recursively from offsets in parents.

Scott Evernden
@Scott: sounds awfully simple when you put it that way :)
elo80ka