bobbel on WebDeveloper.com suggests getting the width of the border by comparing the width of the inner and outer windows, and then subtracting this from the inside — leveling the height to get the size of the window title for the 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;
Of course, this does not guarantee correctness - it is possible that the user has a browser with a bar at the bottom, or window decorations that have different widths on the sides / bottom - but this is an accurate, practical workaround for the top -level of the browser in each browser configuration / default browser window I can think of. (Of course, this will not work for pages in an iframe.)
The right solution for this would be to offer a specification on the whatwg mailing list to make innerScreenX and innerScreenY the standard, as described in the discussion of Chromium 151983's problem regarding the implementation of a similar value for mozInnerScreenX / Y for Chrome. It seems like no one has found time for this, though (although this is a crazy suggestion to implement an asynchronous API function to "calculate" this).
source share