473,394 Members | 2,048 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,394 software developers and data experts.

Position of an object in browser window

Hi Everyone!

I need to get the position coordinate (left and top)of a object (any object, lets say image) in browser window. The position should be with respect to browser window's size i.e we should take care the browser's size, scrolling etc. So the position will be variant if we resize the browser window. Please give me some idea.

I used -
document.getElementById("myImg").getBoundingClient Rect(). But not got proper position.

Also I used but didn't work.

Expand|Select|Wrap|Line Numbers
  1. while (element) {
  2. coords.x += element.offsetLeft;
  3. coords.y += element.offsetTop;
  4. element = element.offsetParent;
  5. }// returning coords
Sep 16 '08 #1
5 1882
gits
5,390 Expert Mod 4TB
you may have a look here ... and see whether that helps?

kind regards
Sep 16 '08 #2
Thanks gits!
But, the example mentioned be you finds the real position. If you resize the page and run the script again, it points to the correct new position of the element.

Actually I am looking to get the position w.r.to browser. Let say my object's actual position is (100,100). When I resize the browser or scroll, I should get current position (say 10,20), not actual position. Can you please tell me?
Sep 16 '08 #3
rnd me
427 Expert 256MB
are you trying to get the object's coords on the screen or the object's coords in the browser?

you talk of resizing the browser is confusing, as that could leave either of the two coords noted above unchanged.

moving the browser window would affect the screen coords, but not the browser coords.

jumping ahead, to get the screen coords, you will have to add in the position of the browser relative to the screen.
Sep 16 '08 #4
are you trying to get the object's coords on the screen or the object's coords in the browser?

you talk of resizing the browser is confusing, as that could leave either of the two coords noted above unchanged.

moving the browser window would affect the screen coords, but not the browser coords.

jumping ahead, to get the screen coords, you will have to add in the position of the browser relative to the screen.
Yes, I wanted to find out the screen coords actually. Thanks!
Sep 17 '08 #5
acoder
16,027 Expert Mod 8TB
Use screenX/screenY - cross-browser compatible too.
Sep 18 '08 #6

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

Similar topics

4
by: Ken Kast | last post by:
Here's my situation. I have a statically positioned table that has an image in a cell. I also have some layers, defined by absolute-positioned DIVs for some animation. Everything works until I...
1
by: Robster | last post by:
I'd to postion a pop up windown to appear in a position relevtive to the centre of the screen, rather than top=200, left=200. Is there any way i can do this? Alternatively i need a script that...
10
by: Danny | last post by:
How can I get the coordinates of the mouse cursor in Mozilla browsers as well as Opera and IE6? I'm struggling to understand how to capture mouse movement events with Mozilla/Netscape/Firefox and...
16
by: Konrad Viltersten | last post by:
Suppose you got a really long page and you'd like to enable the user (supposedly, there's only one but if it's not to difficult we could extend that to any number) not to have to scroll to the...
7
by: Doc | last post by:
I've read in a couple of different places including the archives of this forum that html doesn't allow you to precisely dictate the position of an image, but I found this command (again in the...
1
by: malcolm | last post by:
I have a scrollable vb.net form with a web browser (axWebBrowser) instance on it. All is well until I try to change the left/top (and perhaps height/width) of the web browser on the form. If...
2
by: rockdale.green | last post by:
Hi, I do not know where should I start to solve this problem. I have a calendar inside a div on my webpage which will show /hide when user click a button. but the button is almost at the...
2
by: petermichaux | last post by:
Hi, It seems like determining element position in a web page is a difficult task. In the position reporting source code I've looked at there are special fixes for at least some versions of...
4
by: john | last post by:
Hi to All, I am new to html authoring, so sorry if my terminology is not correct or exact. I would like to position a footer div to the bottom of the browser window. As I research in the web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.