views:

607

answers:

3

Hey all,

For firefox is there anyway to determine the TopLeft location of the "viewport" (ie the client area)? I know the height/width is available via window.innerHeight and window.innerWidth. But I also need to know "innerTop" and "innerLeft" (which don't exist).

Thanks,

Rob

A: 

If you can get a mouse event, you can look at its event.screenX/screenY properties and subtract the event.clientX/clientY properties. This is even cross-browser compatible (DOM Level 2 Events).

bobince
+1  A: 
  • window.innerHeight - The height of the document area.
  • window.outerHeight - The height of the entire window.

You could subtract one from another, and get the distance of the document area from the top of the window, plus the height of the status bar.

scraimer
This is the closest answer so far! Unfortunately the outer height includes all the chrome (top and bottom). Any idea how to get the size of the status bar area at the bottom?
Sorry, I don't know of any way to get it just by querying a value. However, here's an idea: I seem to recall that you can specify whether windows opened by javascript will have a statusbar. You could open one window with a status bar, and another without, and you'll know the height.Of course, you'll have to tie all this to an actual mouse-click, otherwise it'll get blocked by popup blockers...
scraimer
A: 

Try this:

document.documentElement.getBoundingClientRect()

The result of this function will have a left and a top property which will give you what you need.

Note: This function is implemented in Fx3 so you'll need the DOM-traversing offsetParent iteration for older versions.

BYK
Returns 0,0 for top and left.
You seem to ask the question in a wrong manner. When you say "the top left coordinates of the *viewport*" it is exactly this one. You seem to look for something else so I suggest you to clarify your question first ;)
BYK