473,771 Members | 2,372 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Position of an object in browser window

3 New Member
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.getEle mentById("myImg ").getBoundingC lientRect(). 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 1896
gits
5,390 Recognized Expert Moderator Expert
you may have a look here ... and see whether that helps?

kind regards
Sep 16 '08 #2
mani1234
3 New Member
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 Recognized Expert Contributor
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
mani1234
3 New Member
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 Recognized Expert Moderator MVP
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
11019
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 scroll/resize. Then the image "moves" on the screen but the animation doesn't. The net effect is that their relative positioning changes. I'd like to have it be that they would stay in the same relative position. I want to keep the image as an...
1
1861
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 will position the popup in the same place irellevent of browser window and resolution.... Any ideas?
10
18084
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 I've Googled so much my brain hurts. http://www.ghpkendal.co.uk/TestPages/Test.htm Move your cursor over the yellow area and you should see the mouse coordinates echoed above.
16
1618
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 last position in the document he/she was viewing but simply auto-jump him/her to it. Is that doable at all using JS? I guess it would be somewhere in the vicinity of: - remember every scroll - save the line number to the users HDD
7
7989
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 archives of this forum) that apparently allows you to do exactly that. <img src="whateveryourfilelocationis" style="position:absolute; left:Xpx; top:Xpx"> What do you call this command? The responder of the particular message where I found it...
1
1675
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 the form is scrolled so that the top of a browser control is not showing, then the browser is lost. The behavior is especially amusing if part of the browser is visible, and part is above the window. The change works, but the portion of the...
2
28420
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 bottom of my webpage, I am using position :absolute for the div so everytime when the div shows, it will "drop down" cause the vertical scroll bar appears on web browser and the user have to scroll down to see the whole calendar. I was trying to...
2
1984
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 Safari and Opera. I am doing a lot of dragdrop experimentation and in some situations need a position reporting function. The function doesn't need to report the positions of exotic elements like images in button elements; however, I would like a...
4
29389
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 shows this could be done a containing element with "min-height: 100%;" and an absolute positioned element (div) inside, aligned to bottom ("position: absolute; bottom:0px")
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9910
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.