Is there a way to get the position of an element (let's say a button) relative to the entire monitor, not just the page I'm working with? All solutions I've found so far find can find the position of the element on the page, but I'm wondering if I can tell where the button is on the screen as a whole, not just my page.
Asked
Active
Viewed 1,344 times
6
-
Look at [window.screen](https://developer.mozilla.org/en-US/docs/DOM/window.screen) – epascarello Apr 17 '13 at 17:06
-
@epascarello - `window.screen` doesn't seem to have a `left` property in Chrome. It does have screen dimensions, but I can't see anything about the location of the window. – Justin Morgan - On strike Apr 17 '13 at 17:17
-
You can use window.screenLeft – tilleryj Apr 17 '13 at 17:28
2 Answers
1
including taskbars:
window.screen.availHeight
window.screen.availWidth
not including
window.screen.width
window.screen.height
supported on all major mobile devices so if you know where the taskbars sit, its a simple calculation to figure out the difference.... then apply it to jquerys offset function:
$('#myElement').offset().top
$('#myElement').offset().left
or raw js:
var myElement = document.getElementById('myElement');
myElement.offsetTop
myElement.offsetLeft
hope this helps! :)

Daniel Vérité
- 58,074
- 15
- 129
- 156

cjonasw
- 488
- 3
- 7
1
You cannot know where the browser is in the operative system render. Some browsers support it but it's not guaranteed this will work everywhere. And in those that support it there are multiple edge cases that you can't control (like multiple monitors)

fmsf
- 36,317
- 49
- 147
- 195