JavaScript How can I get the screen position of content on the page? [duplicate]

There must be a way of finding this. I need to figure out the coordinates of document.body with respect to a screenThis is as far I have got

I need to figure out the coordinates for the question mark in the image. This will be the position of the document's body with respect to the screen. The image gives a description of the properties I could use. Is it possible?

Answer:1

bobbel on WebDeveloper.com suggests getting the width of the border by comparing the inner and outer window width, and then subtracting that from the inner-outer height difference to get the size of the window header for values you can add to screenX and screenY:

// compute width of borders
var borderWidth = (window.outerWidth - window.innerWidth) / 2;

// compute absolute page position
var innerScreenX = window.screenX + borderWidth;
var innerScreenY = (window.outerHeight - window.innerHeight - borderWidth) + window.screenY;

Granted, that's not guaranteed to be correct - it's entirely possible the user has a browser with a bar at the bottom, or window decorations that are different widths on the sides / bottom - but it's an accurate, practical workaround for the top-level browser window in every default browser/windowing configuration I can think of. (Of course, this won't work for pages in an iframe.)


The proper solution for this would be to propose a spec on the whatwg mailing list to make innerScreenX and innerScreenY a standard, as described in the discussion on Chromium issue 151983 regarding implementing an analogous value to mozInnerScreenX/Y for Chrome. It would appear that nobody has taken the time to do so, though (although there's this crazy proposal to implement an asynchronous API function to "calculate" it).

Answer:2

I am trying to log into a website with Scrapy, but the response received is an HTML document containing only inline JavaScript. The JS redirects to the page I want to scrape data from. But Scrapy does ...

I am trying to log into a website with Scrapy, but the response received is an HTML document containing only inline JavaScript. The JS redirects to the page I want to scrape data from. But Scrapy does ...

  1. execute inline javascript
  2. execute javascript inline html
  3. node execute inline js
  4. javascript execute inline function

newbie javascript question. I made sure to research as much as I could before posting here, I've tried many solutions but could be searching for the wrong thing. I've attached an image below of the ...

newbie javascript question. I made sure to research as much as I could before posting here, I've tried many solutions but could be searching for the wrong thing. I've attached an image below of the ...

  1. loop within loop python
  2. loop within loop r
  3. loop within loop vba
  4. loop within loop stata
  5. loop within loop in c
  6. loop within loop arduino
  7. loop within loop ansible
  8. loop within loop in sap abap
  9. loop within loop matlab
  10. loop within loop javascript
  11. loop within loop
  12. loop within loop java
  13. loop within loop sql
  14. loop within loop abap
  15. loop within loop oracle
  16. loop within loop sql server
  17. loop within loop sas
  18. bash loop within loop
  19. wordpress loop within loop
  20. php loop within loop

on window scrolling the Tooltip should appear correctly above/below/left/right of its parent. Once I scrolled down on my Demo the position of the Tooltip brakes. How can I calculate the y-offset of ...

on window scrolling the Tooltip should appear correctly above/below/left/right of its parent. Once I scrolled down on my Demo the position of the Tooltip brakes. How can I calculate the y-offset of ...

I have the following canvas: Codepen link What I want: Equal margin on both sides of canvas without any horizontal scroll bars. Problem: margin-right property does not to work. I have seen some ...

I have the following canvas: Codepen link What I want: Equal margin on both sides of canvas without any horizontal scroll bars. Problem: margin-right property does not to work. I have seen some ...

  1. margin-right not working
  2. margin right not working css
  3. margin right not working react native
  4. margin right not working android
  5. margin right not working bootstrap
  6. margin-right not working in chrome
  7. margin-right not working in ie
  8. margin right not working in outlook
  9. margin right not working on div
  10. margin right doesn't work
  11. margin-right auto not working
  12. margin-right negative not working
  13. margin right 0 not working
  14. margin right minus not working
  15. margin-right auto not working in ie
  16. html margin right not working
  17. table margin right not working
  18. ionic margin-right not working
  19. margin-right negative value not working
  20. body margin right not working