473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Screen coordinates of object

1
Hi everybody!

I need a script, which calculates screen coordinates of given object (e.g. textbox or div). By "screen coordinates" I mean offset from upper left corner of the screen (not frame or browser window).

Thanks in advance.
Oct 4 '06 #1
11 5286
acoder
16,027 Expert Mod 8TB
Use the screenX/screenY properties.
May 20 '08 #2
hsriat
1,654 Expert 1GB
You won't be able to get that if the HTML is rendered itself. But if you have set the position, and left and top of the elements by CSS (or javascript), only then you would be able to retrieve the x and y coordinates as
Expand|Select|Wrap|Line Numbers
  1. var x = parseInt(elementObj.style.left); 
  2. var y = parseInt(elementObj.style.top);
May 21 '08 #3
hsriat
1,654 Expert 1GB
Use the screenX/screenY properties.
And that was a really old post! ...:D
May 21 '08 #4
Markus
6,050 Expert 4TB
And that was a really old post! ...:D
Must've been bored.

Like me
May 21 '08 #5
acoder
16,027 Expert Mod 8TB
You won't be able to get that if the HTML is rendered itself. But if you have set the position, and left and top of the elements by CSS (or javascript), only then you would be able to retrieve the x and y coordinates as
Expand|Select|Wrap|Line Numbers
  1. var x = parseInt(elementObj.style.left); 
  2. var y = parseInt(elementObj.style.top);
That would give you the x/y coordinates within the browser, not the screen

...and yes, it's an old post, but no-one answered it (poor thing!)
May 21 '08 #6
hsriat
1,654 Expert 1GB
Must've been bored.

Like me
But you don't reply in your own threads... :-/
May 21 '08 #7
hsriat
1,654 Expert 1GB
That would give you the x/y coordinates within the browser, not the screen
oh.. I see... good point..
So one can still calculate the browser's offset wrt the screen by doing
Expand|Select|Wrap|Line Numbers
  1. var offsetX = event.screenX - event.pageX; //(or clientX)
  2. var offsetY = event.screenY - event.pageY; //(or clientY)
And then add that in x and y calculated above...
what say? :p

...and yes, it's an old post, but no-one answered it (poor thing!)
I hadn't joined by the time. :p
May 21 '08 #8
acoder
16,027 Expert Mod 8TB
oh.. I see... good point..
So one can still calculate the browser's offset wrt the screen by doing
Expand|Select|Wrap|Line Numbers
  1. var offsetX = event.screenX - event.pageX; //(or clientX)
  2. var offsetY = event.screenY - event.pageY; //(or clientY)
And then add that in x and y calculated above...
what say? :p
screenX and screenY should be enough, see link.
I hadn't joined by the time. :p
Neither had I ;)
May 21 '08 #9
hsriat
1,654 Expert 1GB
screenX and screenY should be enough, see link.
But still, how would you tell what are the coordinates of a <div> element (for instance) wrt the screen? I'm not getting what you are trying to say.

This is what I understand from screenX and pageX:

May 21 '08 #10
acoder
16,027 Expert Mod 8TB
But still, how would you tell what are the coordinates of a <div> element (for instance) wrt the screen? I'm not getting what you are trying to say.
I see now what you mean. Yes, screenX/Y would give the screen co-ordinates, pageX/Y the co-ordinates relative to the document. However, it's not supported in IE, so you'll have to use clientX/Y plus scrolling offset in IE to get the same value.
May 21 '08 #11
hsriat
1,654 Expert 1GB
I see now what you mean. Yes, screenX/Y would give the screen co-ordinates, pageX/Y the co-ordinates relative to the document. However, it's not supported in IE, so you'll have to use clientX/Y plus scrolling offset in IE to get the same value.

I know its not an IE thing. But while having a logical conversation, we should keep IE out. :D
Of course it would need some fix as usual. :)
May 21 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MLH | last post by:
http://support.microsoft.com/default.aspx?scid=kb;en-us;100973 shows Function Screendump(). It is code that effectively does the same thing as pressing SHIFT-PRTSCR on your keyboard. I am trying...
0
by: phil cunningham | last post by:
Hello, I am looking for a good way to scale real objects on to the screen/printer In our project, objects are created assuming the units are meters. For example, I may have a rectangluar shape...
2
by: Dan Sikorsky | last post by:
How do you get the x,y pixel location of a textbox so that you can position the Web Date Control popup nearby the associated textbox that will contain the date selected by the Web Date Control? ...
3
by: ZorpiedoMan | last post by:
Help... I need the screen coordinates of a control so I can place a pop up form underneath it. --Zorpy *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in...
1
by: zoneal | last post by:
OS: Win XP Language: VB.net or C# I have a program where I need to launch 2 separate instances of an App called "Main.exe". Each instance will need to be piped to there own video display. ...
3
by: steve | last post by:
Hi All I have textboxes within a TableLayoutpanel and I want to be able to position an independant control adjacent to a selected textbox This independent control allows selection of text to...
3
by: Peter Oliphant | last post by:
I'm programming using MS VS VC++ 2008 Express (Beta 2) in /Cli pure mode. I've found the Screen class. With it I can very easily get the count and all the data on the various Screens attached to...
0
by: raylopez99 | last post by:
keywords: logical coordinates, page coordinates, world coordinates, device coordinates, physical coordinates, screen coordinates, client coordinates. offset rectangle. WYSIWYG rubber rectangle...
7
by: raylopez99 | last post by:
I have a logical drawing space much bigger than the viewport (the screen) and I'd like to center the viewport (the screen) to be at the center of the logical drawing space. After following the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.